Posted By: Nicros
Problem with saving a string array (game_save / game_load) - 07/23/15 10:19
Hi,
I try to save my game data using the 'game_save' function.
Every time the save is succesful and when I load the game without
closing the program before, the loading also works.
But if I restart the game and want to load the saved game data, the strings don't load correctly.
Therefore i've wrote a short example code:
Where is the mistake?
Thanks for help
P.S.: deutsche Antworten sind mir auch sehr recht ;-)
I try to save my game data using the 'game_save' function.
Every time the save is succesful and when I load the game without
closing the program before, the loading also works.
But if I restart the game and want to load the saved game data, the strings don't load correctly.
Therefore i've wrote a short example code:
Code:
#include <acknex.h> #include <default.c> STRING* FileNames[256]; int iTest; function saveLevel(); function loadLevel(); function outpRandomString(); function main() { int i; random_seed(0); level_load(""); for(i=0;i<256;i++) FileNames[i] = str_create("testName"); iTest = 1234; on_f1 = saveLevel; on_f2 = loadLevel; on_f3 = outpRandomString; while(1) wait(1); return; } function saveLevel() // saving the complete level { int Save = game_save(str_create("test"),1,SV_ALL); // SV_VARS|SV_POINTERS|SV_STRINGS -> also don't works if(Save <= 0) printf("Error: saving"); } function loadLevel() // loading the save game { int i; // for(i=0;i<256;i++) // FileNames[i] = ""; int Load = game_load(str_create("test"),1); if(Load <= 0) printf("Error: Loading"); printf("iTest: %i",iTest); // correct outpRandomString(); // nothing, rubish or game crash } function outpRandomString() // outputs the string content at a random index { int i = integer(random(256)); printf("Index:%i | String:%s",i,_chr(FileNames[i])); }
Where is the mistake?
Thanks for help
P.S.: deutsche Antworten sind mir auch sehr recht ;-)