2018-07-28 12:54:42

Hi.
I've a bgt problem with saving and loading the game.
Basicly I've a ship class with an array ship@[] ships;
Now, I've a load and save voids in the class.
Let's say I have 2 ships in the array.
When I run the load function it loads all ships, but all of them have same values. Basicly, all of them are the same.
I hope you understand what's the problem and can help me fix it.
Have a nice day.

Don't care.

2018-07-28 14:24:53

That really depends on code. I can't help without any code provided but what you need to do in general is saving all the ships elements using a for loop, and loading them back again. This might sound a bit complex. First in your save function you need to get a for loop that runs through the ships array. Then save every ship with a seperater like :, or |, or _, or what ever you like in between of each to the save file. To load it, you read the contents of the file in a string, and use string_split function to split each element data you saved into an array of string. The last thing to do is to get a for loop from the array string i mentioned and read the data from there. Then spawn ships with that data.

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-07-28 16:12:34 (edited by Stiboly 2018-07-28 16:22:38)

Thanks. I forgot about the string_split. But can you provide code for saving?

Don't care.

2018-07-28 18:20:45

something like this:
string finalstring;
for(uint i=0; i<ships.length(); i++)
{
finalstring+=ships left braket i right braket .hp+":"+ships left braket i right braket .loc_x+":"+ships left braket i right braket .loc_y+":"+ships left braket i right braket .loc_z+"\r\n";
}
file savefile;
savefile.open("save.sav", "wb");
savefile.write(finalstring);
savefile.close();

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-07-28 19:08:25

Thanks. I think I can do the rest my self. Thanks again.

Don't care.