Page 1 of 1

Preserving scenario state across sessions?

Posted: Sun Sep 09, 2018 10:22 am
by SeaQueen
I'm having difficulty with something which isn't LUA scripting per se, but is a problem raised by LUA scripting. It seems that when I save a game, the variables I set in LUA are not retained, so when I reload the scenario it re-initializes them. Has anyone found an adequate way of addressing the problem?

My scenarios tend to have a lot of counters, and perform a lot of math, in order to determine victory conditions, changes in plans, etc.

RE: Preserving scenario state across sessions?

Posted: Sun Sep 09, 2018 12:00 pm
by Whicker
I was wondering about that when I was looking at some of your actions.
I think you need to use keyvalues in order for them to persist across saves:

http://commandlua.github.io/#ScenEdit_SetKeyValue

there is a quirk there about them needing to be stings and not numbers - so I think you have to change them back and forth.

like:

ScenEdit_SetKeyValue("HalfHour", tostring(halfHour));
and then

local halfHour = ScenEdit_GetKeyValue("HalfHour");
halfHour = tonumber(halfHour);

RE: Preserving scenario state across sessions?

Posted: Sun Sep 09, 2018 12:04 pm
by Whicker
not sure how that would work with your tables/objects. I kind of think they should just be individual variables but have never used a table with a keyvalue so not sure.

RE: Preserving scenario state across sessions?

Posted: Sun Sep 09, 2018 12:15 pm
by SeaQueen
Darn... that makes me sad. In some of my other creations which I haven't released, I used SetKeyValue()/GetKeyValue(). I was happy because I thought I'd discovered I could avoid using lots of tonumber() calls and it made my code a little more clear. I guess I was naive.