Making a very simple game, and using autoloads. I want to send a signal from one class like this:
extends Node
var game: Game
signal changePic(newPic: String)
class MazeCell extends Node:
var on_enter:Callable
var maze:Maze
var down: MazeCell=null
var up: MazeCell=null
var left: MazeCell=null
var right: MazeCell=null
#not showing up properly???
func makeMoveDialog():
var optAry:Array[DialogManager.DialogOpt]=[]
var newDialog=DialogManager.DialogLine.new()
newDialog.line=""
if down!=null:
var newOpt=DialogManager.DialogOpt.new()
newOpt.line="South"
#IMPORTANT LINE BELOW!
GameManager.changePic.emit("res://imgs/Gear_3.webp")
And the reciever is here:
class UIDialogManager:
var label
var optNodes:Array[Button]
var textRec
#var dialogManager:
#what's wrong with calling this signal????
func setMainPic(res:String):
print("setMainPic!")
print(label.visible)
When I try to do anything with the label (such as print out info about it) it gives me a null error, even though the node is both in the scene and initialized.
Additionally, I have another signal that CAN use it, and it looks like this:
func _on_opt_button_0_button_up():
var curLine:DialogManager.DialogLine=DialogManager.dialog_manager.get_current_line()
print("Pressed!")
var curOpt=curLine.opts[0]
var nextLine=curOpt.on_pressed.call()
DialogManager.dialog_manager.pop_current_line()
DialogManager.dialog_manager.add_line(nextLine)
uiManager.setMainText(nextLine)
func setMainText(line: DialogManager.DialogLine):
label.text=line.line
The above works totally fine! Can anyone help me figure out what I’m doing wrong? (All classes here are autoloads).
# manager - refs to both nodes wants B to talk to A
Node_b.connect("speak", node_a.listen)
# node A - wants to listen to B secrets, has ref to B
Node_b.connect("secret", self.listen)
Func listen(words):
Print(words)
# node B - something to say
Signal speak(something_to_say:String)
Signal whisper(secret:String)
Speak.emit("hello world")
Secret.emit("password")
I know for a fact that connection is established, the issue seems to be that sometimes the receiver function can access local nodes, and that sometimes it can’t.
It CAN access local nodes when I trigger a signal from a button press (on_button_up, as shown above) but not otherwise (when I call changePic.emit()).
When I call functions from one class (game_manager), it says variables aren’t initialized, but when I call them from another, it says they are. Do you have any idea why this would be?
When I type get_node into the editor, sometimes the param will complete with all the nodes in my scene, and sometimes it will only show me the auto loads. Do you know why this would be? And if there’s an easy way to fix this?
It autocompletes with all the nodes when I write it in my parent, but not when I write it in a child node.
Does the node even exist yet in the current scene or scene tree?
Sometimes the script compiler is getting hung up on checking correctness in the syntax. You may be in the middle of writing an if statement and you haven’t put the “:” yet. Sometimes it gets confused if you close the parentheses before placing a parameter. Maybe there is a bug in another script that invalidates a whole class everywhere it is used. Godot: “I won’t intellisense until the code is right”.
If I was a Godot dev I would only have get_node recurse down the tree for auto complete, and not back up to parents and cousins and grandparents and distant relatives… etc. since that would be bad practice in general to reference ancestors and cousin. Although they don’t stop you from writing an absolute path or a relative path.