BQubed
Member
I'm stuck pretty hard on the issue of coding persistence into my game. Here's the scoop:
This code is situated in Alarm[3] of the parent event of all my interactable instances. It works and successfully adds all those variables to
In Alarm[4] I have this:
This is what I'm using to try and load the variables upon entering the room. Also, inside InteractableParent I have
When I use
This is exactly what I want.
Now here's the issue. Whenever I enter a new room, I don't know what happens to the data loaded into the ds_map. The next room I
This is my first coding of persistency so I may have missed something obvious. If you need to see more code or have any questions, you need only ask.
GML:
/// @description Save to Struct
function npc_data(_name, _xx, _yy, _dialogue_state, _img_index) constructor
{
name = _name //unique instance ID
xx = _xx;
yy = _yy;
npc_dialogue_state = _dialogue_state;
img_index = _img_index;
}
with(InteractableParent)
{
var _inst_vars = new npc_data(name, x, y, dialogue_state, image_index);
var _persist_map = ds_map_add(global.npc_map, name, _inst_vars);
}
global.npc_map
(which is in my persistent game controller object).In Alarm[4] I have this:
GML:
/// @description Load from Struct
if ds_map_exists(global.npc_map, name)
{
x = global.npc_map[? name].xx;
y = global.npc_map[? name].yy;
dialogue_state = global.npc_map[? name].npc_dialogue_state;
image_index = global.npc_map[? name].img_index;
}
alarm[3] = 1
at the end of the create event which is to have all active instances send their variables to the ds_map.When I use
show_message(global.npc_map[? name])
I get:This is exactly what I want.
Now here's the issue. Whenever I enter a new room, I don't know what happens to the data loaded into the ds_map. The next room I
show_message(global.npc_map[? name])
I get the same thing but for the instances in the current room, but not the former. I don't know if the map is being overwritten or what, but even though the variables are saved properly and I can pull them individually via show_debug commands, the rooms always revert back to the original.This is my first coding of persistency so I may have missed something obvious. If you need to see more code or have any questions, you need only ask.
Attachments
-
5.1 KB Views: 3