how would I call the save() function in the KinematicBody2D?
Your save_game function is calling the save() function on your player. The code snippet I posted shows the part of the code that's doing that. Maybe we'll break down the lines and see what's happening:
var savenodes = get_tree().get_nodes_in_group("Persist")
-Here we create the variable 'savenodes' and have it become an array containing all the nodes that have been added to the "Persists" group. if you followed this line with
print(savenodes), you should see an output that looks like
for i in savenodes:
-Here we iterate through each item in our list called savenodes, and call the code indented below it for each item, calling that item "i"
var nodedata = i.save()
-This is where we're getting the actual data to save from the player. if "player" = "i", than "i.save()" can translate into "call
save() on the player object". When you have more objects in your Persists group, this line will be called on each one. Each time, it will create this variable
nodedata which contains a dictionary of that node's data (everything that's returned from the
-This takes that nodedata and writes it to your save file
could I use all of this save script of in the globalscript and if I did how would I call it?
Yes, absolutely! If your save_game() code exists in a singleton you call "Data", you just call it (from anywhere!) with
Hopefully the first answer answers your third question :)