Could you use an AutoLoaded class to store that info and retrieve it from there instead?
So you could have:
# initialize as empty Vector2
var player_position = Vector2()
Then in other scripts, whenever you change the player position, you can set also the value:
$Player.position = new_position
AutoloadedClass.player_position = new_position
And retrieve the value the same way:
$Player.position = AutoloadedClass.player_position
Godot autoloading documentation
Thank you for your answer! I pretty much did this and it seems to be working. I kept the local save function, just gutted it down to four lines that grabbed values from the variables I was having trouble getting, and then called the global save function and passed it to them. That part’s working great.
Loading is kind of the same thing in reverse. The global load function does all the global variables for player, world state, dialogue tree, etc, then it needs to call the local load function, pass it those same variables, and let it put them where they belong and reset all the NPCs etc (one of those variables is a dict of all the relevant information for all of them).
The only problem I’m still having is calling the local load function from the global one (same reason as before) but it’s a smaller issue now, and worst case, I’ll try using a signal to get the data to it. Since I change scenes first, the only thing listening for the signal should be the correct local load function.
I think part of the reason I’m having such trouble with paths is that the autoload/global save_load script isn’t directly in the hierarchy, and I’m using the level changing code from Singletons (AutoLoad) — Godot Engine (3.0) documentation in English which seems to work with the actual files, and I’m not sure how to get their paths to work in gdscript.
Thank you again for your help, I really appreciate it!
jevans | 2019-02-04 18:23
Just for future reference for anyone has this problem, I didn’t end up using signals, I just had the global load function return the variables (in a dictionary, though an array would also work), then had the GUI pause menu script that called it convert them into individual variables and call the level-local load function to put them where they belonged.
This is probably not the right way to do this, but that’s kind of this game’s motto at this point, so at least it’s on brand.
var dict= Global_Save_Load.load_game() #this one's the autorun
var flexible_save=dict["flexible_save"] #this has all my NPCs' locations on paths, etc
$"../.."/Save_Load.load_game(flexible_save, pos_x, pos_y) #this one's local to the level/instance
The way the level changing code works is to load new instances from the files, so the levels aren’t ever really in the same editor tab as the autoruns. I had trouble figuring out paths, and setting up the signals was difficult because the autoruns couldn’t see everything else, even though the local files can call on them. Bouncing all those values back through the pause menu seemed like the most efficient way to get the values from the global save function to the level-local one.
I only used a dictionary because I was troubleshooting an issue with the player’s position and didn’t want to worry I was doing something wrong with the order of values in the array.
jevans | 2019-02-04 21:27