Frictional Games Forum (read-only)
Save data - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: SOMA (https://www.frictionalgames.com/forum/forum-55.html)
+--- Forum: User created content (https://www.frictionalgames.com/forum/forum-79.html)
+---- Forum: Development (https://www.frictionalgames.com/forum/forum-82.html)
+---- Thread: Save data (/thread-31371.html)

Pages: 1 2


Save data - Kanthos - 10-18-2015

Hey guys, it´s me again ^^

So i came over an interesting problem: I want to save a global variable from one map, because i want to return to this map later on.

So my first idea was to read and write into a txt-file via the fstream function. This does not work, because fstream seems not to be supported.

Later i saw the fuction LastOnSoma_SetText(tString), which i suspect to be a similar instruction, but couldn´t find it in the scripts.


Was anyone of you already in that stuff and has some advice?

Greets!


RE: Save data - Romulator - 10-18-2015

I don't know specifically what the global variable syntax is, but LastOnSoma_SetText(string) is used for the Loading Screen when you specify what section of the story the player is up to.


RE: Save data - Kanthos - 10-18-2015

I see :/ thanks Modulator


RE: Save data - Kanthos - 10-19-2015

Modulator, do you know where LastOnSoma_SetText is defined? Wanna throw a look at it.


RE: Save data - Romulator - 10-19-2015

As in, where it appears in Frictional Games' code? Of course! Most are probably located in OnStart(); however some change later on in the map. Here's an example from theta_exit.hps, where they have two instances of changing the SetText.

PHP Code:
void OnStart()
    {
    
//Unrelated Code Here
    //
        //////Level Audio and Preloads    
        
Sound_PreloadProject("02_07_theta_exit_a");
        
Sound_PreloadGroup("Flashback/Level/02_07"true);
        
        
LastOnSoma_SetText("02_07_theta_exit_1");
    }

    
void SequenceWakeup(const tStringin asName)
    {
    
//There is lots of code here for this sequence. Good job FG! o.0
    //This particular part seems to be when you detach from the wall.
    
Player_SetFlashlightDisabled(false);    
        
    
LastOnSoma_SetText("02_07_theta_exit_2");
    } 

As we can see here, in the first instance, the LastOnSoma_SetText(); string is changed to become an entry called "02_07_theta_exit_1" when entering the map. Which would be located in the config/english.lang file. And sure enough, it is. (Spoilered and removing other entries for obvious reasons).

Spoiler below!
Code:
<CATEGORY Name="LastOnSOMAText">
    <Entry Name="02_07_theta_exit_1">Simon is lost somewhere inside Theta, looking for a way out.</Entry>
    <Entry Name="02_07_theta_exit_2">Simon is lost somewhere inside Theta, hunted by strange creatures.</Entry>
</CATEGORY>


I've included the second instance it changes also because it appears that you can change it at any time. Handy!

In a way, it is a global variable, since such text is stored in memory within the save. It is setting the string to display when you hit continue or load game. Here's another example from earlier on in the game (pardon the twitch chat. Sourced from Kreekakon's stream).

Spoiler below!
[Image: f336ef1318.jpg]

This particular string appears in the english.lang file, with this entry.
Spoiler below!
Code:
<Entry Name="01_04_transport_station_2">Simon's shuttle has crashed and he now has to find another way to get to Lambda, the place where Catherine, the woman on the radio, is waiting for him.</Entry>


And... well, that's how that particular thing works. The value is saved in memory whenever the game autosaves or the player presses Save and Exit, and is then set for when the Player returns to the game should they need a reminder of where they are.


RE: Save data - Kanthos - 10-19-2015

Thanks, Mod! Smile This will help me a lot!


RE: Save data - jens - 10-19-2015

Saving a global variable you do with cScript_SetGlobalVar... for example cScript_SetGlobalVarInt("MyInt", -4); and then cScript_GetGlobalVarInt("MyInt");


RE: Save data - Kanthos - 10-19-2015

Hey jens, thanks for your reply!
Do you have a hint how to best "store" such a global variable?

I want that the player of my mod can go to an other map, do things, then return to the first map, but the lights he turned on at its first visit are still on and not reset to the initial map configuration (for example).


RE: Save data - Mudbill - 10-19-2015

That's what he just explained. You store a global variable using cScript_SetGlobalVarInt for example.
You do not need to save a text file or whatever. The global variable is likely saved within the story's Autosaves.

Use this to save your variable:
PHP Code:
cScript_SetGlobalVarInt("MyInt"1); 

Then use this to check what the variable is, in another map if need be:
PHP Code:
if(cScript_GetGlobalVarInt("MyInt") == 1



RE: Save data - Kanthos - 10-19-2015

I quick-tested it and it has not worked :/ Did the same thing that you mentioned, Mudbill.