Preserving scenario state across sessions?

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
SeaQueen
Posts: 1338
Joined: Sat Apr 14, 2007 4:20 am
Location: Washington D.C.

Preserving scenario state across sessions?

Post 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.
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Preserving scenario state across sessions?

Post 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);
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Preserving scenario state across sessions?

Post 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.
User avatar
SeaQueen
Posts: 1338
Joined: Sat Apr 14, 2007 4:20 am
Location: Washington D.C.

RE: Preserving scenario state across sessions?

Post 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.
Post Reply

Return to “Lua Legion”