For example, say you have a condition that is triggered, and you need to check how often the condition occurs at some later time. Or you need to 'teleport' units.
The command set is "ScenEdit_SetKeyValue()/ScenEdit_GetKeyValue()".
In a recent case, I used this to keep track of how many times I created a particular unit. The things I needed to keep track of were the name of the unit, the database type, maximum number to create and how many have already been created. So when the scenario is first started, I ran the following script to initialize it:
Code: Select all
ScenEdit_SetKeyValue("CanberraAir", "dbid=673, maxNum=10, curNum=0");
Code: Select all
-- get the current settings and decode the values
local drop = ScenEdit_GetKeyValue("CanberraAir");print(drop);
local t = {}
for k, v in string.gmatch(drop, "(%w+)=(%w+)")
do
t[k] = v
end
-- deploy one unit
local lastN = tonumber(t['curNum']);
if lastN == nil then
lastN = 0;
end
lastN = lastN +1;
if lastN > tonumber(t['maxNum']) then
ScenEdit_MsgBox('All troops landed',0)
return
end
local veh =ScenEdit_AddUnit({type = 'Facility', name = 'Assault #' .. lastN,
heading = 0, dbid = t['dbid'], side = 'RAN', Lat=new.lat, Lon=new.lon});print(veh)
-- create string with new value to store
local b="curNum="..tostring(lastN)
-- replace the existing string
local a=string.gsub(drop,"curNum=%d", b)
ScenEdit_SetKeyValue("CanberraAir", a);
I have a Steam Workshop scenario under michaelm75 that demonstrates this.
Hope this is helpful.