Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MIITRIN on Mon 01/08/2022 23:09:31

Title: (Solved) Is there any way to implement persistent variables?
Post by: MIITRIN on Mon 01/08/2022 23:09:31
As it stands, the only way to save a variable's value after the game is exited is by saving, but what if you want to save a specific variable without having to actually save and then load that file?

I know writing to a text file is also an option, but that would then leave my variables open to being modified by the user, which isn't ideal either.

Some uses for persistent variables could be stuff like: in-game achievements, a stats screen, and ways of always remembering the user's choices in-game.

Its fine if there's no way of doing this, I'm just personally curious if anyone has made a module or plug-in for this yet.
Title: Re: Is there any way to implement persistent variables?
Post by: Crimson Wizard on Mon 01/08/2022 23:54:37
Quote from: Mintaro on Mon 01/08/2022 23:09:31
I know writing to a text file is also an option, but that would then leave my variables open to being modified by the user, which isn't ideal either.

The common way to do this is to write a binary file instead, using File.WriteInt / ReadInt (or RawInt/RawChar) functions. Technically these may also be modified if someone figures out data format, of course, but so are saves and everything else.

https://adventuregamestudio.github.io/ags-manual/File.html
Title: Re: Is there any way to implement persistent variables?
Post by: MIITRIN on Wed 03/08/2022 10:52:12
That works! Thank you. I wasn't sure exactly how useful creating a file would be, but its actually really simple thanks!