Sites


Creating Point and Click Games with Escoria

Implementing savegames

Savegames are .esc files that set the global environment as necessary, load the current screen, and move the player to the last position.

On a higher level, save files are implemented in the file globals/save_data.gd as numbered "slots". Each slot represents a save file, and has a saved date. The save_data object can be used as a member of the /root/vm scene. The save_data API is asyncronic, to allow for implementations that might require time to complete the operations (like network saving, or saving on consoles). All calls receive a callback that is called when the operation is complete.

Retrieving the slots

To retrieve the available slots, use "get_slots_available":

onready var vm = get_node("/root/vm")
func retrieve_slots():
vm.save_data.get_slots_available([self, "slots_retrieved"])

func slots_retrieved(p_slots):
# p_slots is a dictionary, it can have sparse keys
for key in p_slots:
print("slot ", key, " saved on date ", p_slots[key].date", "! :D")

Loading a slot

To load a slot, use the function "load_slot" in the /root/vm node

func load_pressed(p_slot_n):
vm.load_slot(p_slot_n)
# this will automatically call the "menu_collapse" event and start the new game

Saving

To save the game to a slot, first retrieve the save data information from the /root/vm node using the "save" method, then use the "save_game" method, not the save_data object.

func save_pressed(p_slot_n):
if !vm.can_save():
return # maybe show an error? the vm is not ready to save
var data = vm.save()
vm.save_data.save_game(data, p_slot_n, [self, "game_saved"])

func game_saved(err):
if err != OK:
# error :(
pass
update_ui() # this could call "get_slots_available" again, since the slots changed

Low level savegames

To load directly from a file, of the method "load_file" in the /root/vm node

vm.load_file("user://path/to/save.esc")

When a game is started, this method is used to load the file res://game/game.esc

To save directly to a file, first retrieve the data to save from the /root/vm node using the save() method, then write to a file. The data to save can be a string, or an array of strings, in that case save each string separately.

var data = vm.save()
var file = File.new("user://path/to/save.esc", File.WRITE)
if !f.is_open():
# error!
return FAILED
if typeof(data) == typeof([]): # data is an array
for s in data:
f.store_string(s)
else: # data is a string
f.store_string(data)
f.close()
return OK

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.