Your code made a copy of the name in the second autoload and never updated it. Variables (especially null ones) don’t behave like references.
So here is what happened:
Your game starts. The first autoload is initialized (assuming it is first in the list of autoloads!).
Then the second autoload initializes, by creating its dictionary and copying the name found in the first autoload, which is null.
Then your first scene is loaded. You input the player name, which modifies globals.player_name. But the text for the second scene was already built with null, it has no reason to change magically.
The second scene starts and you’ll see null.
To fix this, a few options:
Don’t copy the the name and do something like .replace("<player>", global.player_name) on the string to show when you actually display it
Don’t make your scene text an autoload. Make it initialize when the scene actually loads (in _ready for example), this way the name will be up to date if you set it before loading it.
Thanks a lot for the help, and sorry for the late reply!
And sorry to bother you again, but I can’t seem to get replace() to work… (・_・ヾ
I’ve added a ‘var playerName’ variable to my page script and changed ‘str(global.player_name)’ to ‘str(playerName)’ and then I added a line of code to this section
…that’s still just returning ‘null’ and I’m 100% sure I’m doing it completely wrong - I’ve also tried writing it out a few different ways.
I can’t really find anything in the docs or other places online on how to properly use replace() ( ̄▽ ̄*)ゞ
Could you possibly help me out with this? Again, sorry for the late response and thank you!
Clamarii | 2020-09-23 06:23
You didnt choose the easiest option tho^^
That extra code you added still does not work because replace does NOT modify a string, instead it returns a modified copy, so you would have to write this instead:
This isn’t causing any errors, but it’s still returning ‘null’.
I thought that maybe I was placing it in the wrong script so I tried placing it in my textBox.gd in ‘func _process(delta)’ but it returns the error ‘Invalid type in function ‘replace’ in base ‘String’. Cannot convert argument 2 from Nil to String.’ …So I’m just… not going to do that. ( o > o)
Yeah - I think I should probably just add the pages to _ready.