GameMaker [SOLVED] Storing large amounts of data inside a script

J

JulianS

Guest
So I am creating a quest system.
A quest can have a title, a questlog of the storyline and some commands like for example "Find the blue flower".
My first Idea was to just create a DS-Grid, with all these Strings in it, which worked but then all this data, which has the potential to get very big is always stored in the RAM.
I also thought about creating an Included File with all this data in it but then i had the idea to just store the data inside a script and just use a giant switch-case construct to get the string i want by calling it with a parameter.

My question now is: Does GameMaker Studio 2 load all scripts into RAM on gamestart or not?
Because then it would not make a real difference to my first solution (using a DS-Grid) and I would think about doing this via an Included File instead.
 
Last edited by a moderator:
H

Homunculus

Guest
As far as I know, it does (at least with a VM export), so you are not solving anything by hardcoding the strings.

If your game does not require the quest data loaded at all times, you could probably split it into multiple external files that get loaded on demand depending on some specific aspect of your game.
Example: have a quest file for every area of your game, and only load the file with the quests belonging to the area your player is currently in (+ all the player active quests). It's really a problem of identifying at what specific time may need the quest data in your game, and when you do not.

The first thing I'd do though, is have a measure of the actual size of the data. You may assume that having all of your quests loaded takes a lot of ram, but if for all practical purposes that's not the case, why bother with preemptive optimization? Generate a dummy quest, duplicate it a number of times that estimates your final amount, and see how much RAM it takes to store everything.
 

NightFrost

Member
It is unlikely your quests will eat any appreciable amounts of memory, for example compared to graphics. Once you've got several hundred thousand lines of quest text, then it may be the time to start thinking about adding partial loading in the future.
 
A

Annoyed Grunt

Guest
I would really not worry about it... you can store the entirety of War and Peace in ram with only ~4 megabytes.

Here you can try it for yourself

Code:
str = ""
text_file = file_text_open_read("war_and_peace.txt");

if text_file == -1 {
    show_debug_message("File not found.");
    exit;
}

while(!file_text_eof(text_file)) {
    str += file_text_readln(text_file);
}

show_debug_message(string_copy(str, 1, 1000));

buffer = buffer_create(1, buffer_grow, 1);
buffer_write(buffer, buffer_string, str);
size = buffer_get_size(buffer);
size_in_mebibytes = size / power(1024, 2);

show_debug_message("Size (bytes): " + string(size));
show_debug_message("Size (MiB): " + string(size_in_mebibytes));
And you can download War and Peace here.
 
Z

zendraw

Guest
your ram is for that, to store things in it. no matter how meny quests you have it wont be so much that it wuld cause a problem.
 
J

JulianS

Guest
I would really not worry about it... you can store the entirety of War and Peace in ram with only ~4 megabytes.

Here you can try it for yourself

Code:
str = ""
text_file = file_text_open_read("war_and_peace.txt");

if text_file == -1 {
    show_debug_message("File not found.");
    exit;
}

while(!file_text_eof(text_file)) {
    str += file_text_readln(text_file);
}

show_debug_message(string_copy(str, 1, 1000));

buffer = buffer_create(1, buffer_grow, 1);
buffer_write(buffer, buffer_string, str);
size = buffer_get_size(buffer);
size_in_mebibytes = size / power(1024, 2);

show_debug_message("Size (bytes): " + string(size));
show_debug_message("Size (MiB): " + string(size_in_mebibytes));
And you can download War and Peace here.
Thanks for your answer. I now think that it isn't that of a problem now.
By the way: Your link doesn't work :(
 
J

JulianS

Guest
Thanks for your replies.
For all of you interested: I now did it with two DS Maps, one for the changeable data, like the current state in the quest, and one for the Strings, which could maybe be saved and loaded later if needed.
One lesson learned: To not worry about performance issues too much, if it blocks development or takes the fun out of it. :)
 
Last edited by a moderator:
Top