• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Saving random amount of NPCs

with (pNPC)
{
var map = ds_map_create();
ds_list_add(rootList, map);
ds_list_mark_as_map(rootList, ds_list_size(rootList)-1);

if instance_exists(object_index)
{
var objName = object_get_name(object_index);

ds_map_add(map, "ObjectName", objName);
ds_map_add(map, "NPC", object_index);
ds_map_add(map, "X", x);
ds_map_add(map, "Y", y);
ds_map_add(map, "Name", name);
ds_map_add(map, "Bothered", bothered);
ds_map_add(map, "QuestsDone", questsDone);
}
}

Whats the best approach for saving NPCs, who might come and leave the map? Added if to save only NPCs on the map, but I dont know if that is needed or there is better approach.

pNPC is core NPC, or in other words parent NPC, which is parent of all objects and I dont know what game is doing, does it take all objects inside the parent, or just active ones

and how do I load NPCs?

var buffer = buffer_load("Save.txt");
var stringToLoad = buffer_read(buffer, buffer_string);
buffer_delete(buffer);
var wrapper = json_decode(stringToLoad);
var list = wrapper[? "ROOT"];

for (var i = 0; i < ds_list_size(list); i++)
{
var map = list[| i];

var npc = map[? "ObjectName"]; //
var obj = map[? "ObjectID"];
if object_exists(obj)
{
with (npc)
{
x = map[? "X"];
y = map[? "Y"];
name = map[? "Name"];
bothered = map[? "Bothered"];
questsDone = map[? "QuestsDone"];
}
}

This method gives only exception
 
Last edited:
with (pNPC)
{
var map = ds_map_create();
ds_list_add(rootList, map);
ds_list_mark_as_map(rootList, ds_list_size(rootList)-1);

if instance_exists(object_index)
{
var objName = object_get_name(object_index);

ds_map_add(map, "ObjectName", objName);
ds_map_add(map, "NPC", object_index);
ds_map_add(map, "X", x);
ds_map_add(map, "Y", y);
ds_map_add(map, "Name", name);
ds_map_add(map, "Bothered", bothered);
ds_map_add(map, "QuestsDone", questsDone);
}
}

Whats the best approach for saving NPCs, who might come and leave the map? Added if to save only NPCs on the map, but I dont know if that is needed or there is better approach.

pNPC is core NPC, or in other words parent NPC, which is parent of all objects and I dont know what game is doing, does it take all objects inside the parent, or just active ones

With same note, is there way to format json? cause saving into file gives a one long line.
weird, tried to edit, never the less, pNPC is parent NPC of all NPCs
 
Top