(Solved) Is there any way to implement persistent variables?

Started by MIITRIN, Mon 01/08/2022 23:09:31

Previous topic - Next topic

MIITRIN

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.

Crimson Wizard

#1
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

MIITRIN

That works! Thank you. I wasn't sure exactly how useful creating a file would be, but its actually really simple thanks!

SMF spam blocked by CleanTalk