Attention | Topic was automatically imported from the old Question2Answer platform. | |
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.
https://godottutorials.pro/godot-strategy-game-tutorial/
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
ui.update_resource_text()
ui.on_end_turn()
I’ve checked spelling in the UI.gd 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.