Post by Power Supersport on May 26, 2017 15:27:55 GMT
The forum members seem to get too lost when it gets the point when they need a Save / Load system...
First, to disclaim the most misconcepted part in that thread... You CANNOT save a level as an image... What I mean is that you can't just say "Save" and it magically saves everything as it is... There's no such thing... You have to save every single detail you want to further load...
Let's say you have a character and you want to save its position... You have to save its X, Y and Z coordinates, as well as it's rotation coordinates, although they aren't necessary... Every single object you want to be remembered, you need to save its properties somehow...
Here's how you save into a file...
Your file would look like that:
iFileValueWrite is the function that saves a line into the file... To write more lines you can simply repeat the function like that...
In this case your file would look like that:
In the same way you can save strings... For that you need the function iFileStringWrite just like that...
Your file would look like that:
Reading a file is the absoulte same, but you replace the word Write with Read... Let's assume you have that file for reading...
You can read its properties by using the following...
As this tutorial gets very long already, I am going to jump to some practical use...
Let's say you have a character and you want to be able to save its presence on the map... For a basic character, the important properties you want to save are position and rotation... If you have ammo, stamina, health or other extra parameters, you need to save them aswell... Again, there's nothing like a complete level save...
A position has 3 parameters - X, Y, Z
A rotation has also 3 parameters - X, Y, Z
The easiest way of implementation is to save every element as a new line like that...
So, jumping into code, saving would look like that...
Lets assume that your character's position is -91.23 / 3.01 / 108.102 and your character's orientation is 0.1 / 45.12 / 0.4... Your save file would look like that...
Reading from that file is similar to writing
That's the basics of making a Save / Load file system... I hope you appreciated my 1 hour of time to try and explain in detail...
For more information, visit the script object reference: 3drad.boards.net/page/script-reference
First, to disclaim the most misconcepted part in that thread... You CANNOT save a level as an image... What I mean is that you can't just say "Save" and it magically saves everything as it is... There's no such thing... You have to save every single detail you want to further load...
Let's say you have a character and you want to save its position... You have to save its X, Y and Z coordinates, as well as it's rotation coordinates, although they aren't necessary... Every single object you want to be remembered, you need to save its properties somehow...
Here's how you save into a file...
int File = iFileWriteOpen (".\\myfile.txt");
iFileValueWrite (File, 1, true);
iFileClose (File);
Your file would look like that:
1
iFileValueWrite is the function that saves a line into the file... To write more lines you can simply repeat the function like that...
iFileValueWrite (File, 1, true);
iFileValueWrite (File, 2, true);
iFileValueWrite (File, 5, true);
In this case your file would look like that:
1
2
5
In the same way you can save strings... For that you need the function iFileStringWrite just like that...
iFileStringWrite (File, "something", true);
iFileStringWrite (File, "cool", true);
Your file would look like that:
something
cool
Reading a file is the absoulte same, but you replace the word Write with Read... Let's assume you have that file for reading...
2
something
You can read its properties by using the following...
int somevalue = 0;
string somestring = "";
int File = iFileReadOpen (".\\myfile.txt");
int somevalue = iFileValueRead (File);
iFileStringRead (File, somestring);
iFileClose (File);
As this tutorial gets very long already, I am going to jump to some practical use...
Let's say you have a character and you want to be able to save its presence on the map... For a basic character, the important properties you want to save are position and rotation... If you have ammo, stamina, health or other extra parameters, you need to save them aswell... Again, there's nothing like a complete level save...
A position has 3 parameters - X, Y, Z
A rotation has also 3 parameters - X, Y, Z
The easiest way of implementation is to save every element as a new line like that...
positionX
positionY
positionZ
rotationX
rotationY
rotationZ
So, jumping into code, saving would look like that...
Vector3 Location;
Vector3 EulerAngles;
Quaternion Orientation;
iObjectLocation (OBJ_X, Location);
iObjectOrientation (OBJ_X, Orientation);
iQuaternionToEulerAngles (Orientation, EulerAngles.x, EulerAngles.y, EulerAngles.z);
int File = iFileWriteOpen (".\\myfile.txt");
iFileValueWrite (File, Location.x, true);
iFileValueWrite (File, Location.y, true);
iFileValueWrite (File, Location.z, true);
iFileValueWrite (File, EulerAngles.x, true);
iFileValueWrite (File, EulerAngles.y, true);
iFileValueWrite (File, EulerAngles.z, true);
iFileClose (File);
Lets assume that your character's position is -91.23 / 3.01 / 108.102 and your character's orientation is 0.1 / 45.12 / 0.4... Your save file would look like that...
-91.23
3.01
108.102
0.1
45.12
0.4
Reading from that file is similar to writing
Vector3 Location;
Vector3 EulerAngles;
Quaternion Orientation;
int File = iFileReadOpen (".\\myfile.txt");
Location.x = iFileValueRead (File);
Location.y = iFileValueRead (File);
Location.z = iFileValueRead (File);
EulerAngles.x = iFileValueRead (File);
EulerAngles.y = iFileValueRead (File);
EulerAngles.z = iFileValueRead (File);
iFileClose (File);
iObjectLocationSet (OBJ_X, Location);
iQuaternionFromEulerAngles (Orientation, EulerAngles.x, EulerAngles.y, EulerAngles.z, "xyz");
iObjectOrientationSet (OBJ_X, Orientation);
That's the basics of making a Save / Load file system... I hope you appreciated my 1 hour of time to try and explain in detail...
For more information, visit the script object reference: 3drad.boards.net/page/script-reference