Multiple errors doing tutorial, null instance, shadow variables, remote node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By floatingdev

I’ve completed this tutorial but my project is getting a few errors and I can’t see any difference between the example project and my code, which is frustrating.

Debugger says this line running the a ui update function has:
Attempt to call function ‘update_resource_text’ in base ‘null instance’ on a null instance.

extends Node2D

onready var ui : Node = get_node(“UI”)
onready var map : Node = get_node(“Tiles”)

func _ready ():

# update the UI when the game starts

I’ve checked spelling in the script which other forum answer suggested, but otherwise this error is just another puzzle. The UI object should exist, how can it be null? Why would it matter just run the function?

Also, this section of code

class Building:

# building type
var type : int

# building texture
var iconTexture : Texture

# resource the building produces
var prodResource : int = 0
var prodResourceAmount : int

# resource the building needs to be maintained
var upkeepResource : int = 0
var upkeepResourceAmount : int

func _init (type, iconTexture, prodResource, prodResourceAmount, upkeepResource, upkeepResourceAmount):
	self.type = type
	self.iconTexture = iconTexture
	self.prodResource = prodResource
	self.prodResourceAmount = prodResourceAmount
	self.upkeepResource = upkeepResource
	self.upkeepResourceAmount = upkeepResourceAmount

Gets the ‘shadowing already defined variable’ error, but of course, only in my project not the exact same example project.

A clue may be that in the inspector I get the ‘remote node 1277’ object and caution sign that ‘it cannot be edited’, which also is cryptic jargon but may be related.

I even copied the code from the working example project, same errors, which is frustrating. Very.

:bust_in_silhouette: Reply From: Inces
onready var ui : Node = getnode("UI")
func _ready ():

this is corrent, but how does your scene tree look like ? It is there when spelling may be incorrect. Node named “UI” ( all caps ) is supposed to be child of scripted node above.

Building script is obviously shadowing variables. init arguments should be preceded with underscore “_” to mark variables as local. Are You sure it wasn’t like this in tutorial ?

Thanks for the response.

This was helpful and I have been able to move on now.

floatingdev | 2022-08-15 19:42