0 votes

I have a scene made by only 20 labels and one generic node called "global".
Global node will have a script that is autoloaded and also called global and will consist of a function and variables from the 20 labes that will be accesible by all the other scripts I'll make.
What I want is to make text appear in the node that's lower on the screen and then as that node's text is updated, the previous text will appear in the node above it as a kind of history of all the text I printed.
For that I wanted to make the lower label say "Hello world!" when the program starts, using global script. Of course I could use that label (which is called CurrentLine cause the user will be able to write commands), use the _ready function of that label and tell it to print that but what I actually want is to make that script which will imitate the boot log of an OS, and it will push the text from line2 to line3 to line4 whenever a new line of text appears.

But I can never get the reference to any node correctly. With my last program I had the same problem but it was a lot simpler and didn't really need to reference any node so much.
I first tried (naive me) with

var CurrentLine = get_node("CurrentLine")

and then in the _ready() function

CurrentLine.set_text("Hello World!")

It apparently cannot set_text to null base.
So I changed the "CurrentLine" with "res://Content/Scenes/Main.tscn/CurrentLine" but I had no luck so it didn't work either.
Then I tried initializing a variable in global called CurrentLine, then create script for the CurrentLine label and in there

global.CurrentLine = get_node()

But that's not working either. I even changed the () to (self) and ("CurrentLine") but it doesn't work either.
And I can't seem to find anywhere on the internet a page where they tell you explicitly how to reference one node (CurrentLine) from another script (global) that doesn't extend CurrentLine.

In my last program I could make every LineEdit change a variable in it's own global script which stored those values to use them in a different scene.
But it wasn't really referencing those LineEdit's but the global script itself.
In this case I want the global script to keep track of the text in the CurrentLine (where the player will write commands) and push it to the above label, and the text in that label above, push it to the label about that one and so on and so forth until it reaches label20 where the screen ends and it just gets deleted. And also I want to create some sequences of text lines like the one sequence I said it would imitate boot logs from linux live CDs.
But I can't do that if I can't get a reference to each and every label so PLEASE HELLLLPPPPPPP!!!

in Engine by (67 points)

3 Answers

0 votes

get_node takes NodePath as argument. If it's returning null, then node can't be found so NodePath is wrong or Node doesn't exist.

by (379 points)

It does, and after updating it still doesn't work.

https://imgur.com/a/FT3npaW

I have 20 labels, CurrentLine, and 19 history lines.

I think I can do this without referencing them but it'll be quite inconvenient.

That should not be happening, which version of Godot are you using? Is it 3.0.6?

I was using 3.0.2, but I now installed 3.0.6 and it's still happening.

I'm so sorry but that's over me, maybe I'm missing something, can't figure out why is that happening.

It's okay, I'll try the other way, and also I'll ask godot for support.
Thanks a lot for your time!

0 votes

For referencing nodes in the inspector:

export var path_to_my_node: NodePath
onready var my_node = get_node(path_to_my_node)

Please reduce and specify your question.

by (211 points)
0 votes

make a Globals.gd autoload and add:

var node_i_need_reference = null

than on the node you add:

func _ready():
    Globals.node_i_need_reference = self

That will work across scripts etc... inside the same script a simple

var my_node = $MyNode
my_node.method()
print("node name :", my_node.name)
my_node.visible = true

should work...

to add a child tho, you will need to reference the packedscene and instance it:

export var my_node:PackedScene ##drag scene to properties window
instance_of_node = my_node.instance()
add_child(instance_of_node)
by (362 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.