Forum
Stranded II Scripts Saving local variables?Saving local variables?
9 replies 1
Technically it doesn't make too much sense to take over any local variables from one map to another because a new map has other objects than the old one. The only exception is maybe the player unit but unfortunately it's not possible for that either.
So if you want to do something like that you would have to script a workaround. The best way I can think of would be to store local variables in global variables manually before leaving the old map and then setting them back as local variables after loading the new map.
You can use getlocal and setlocal for that.
Anyway, I don't want to carry local variables to other map. Contrary, I want them remain on their place and keep their values. Aren't they saved together with the whole map?
If not, I will try Your idea.
Unfortunately savemap does only save global variables. In thise case I'm not even sure why as it would make sense to be able to save local variables as well
And you're wrong about the worthiness. You play my stuff and you even use it to create new stuff. Two things I highly appreciate. So you totally can expect to get an answer from me.
I'll try to move all variables into global. If this works, I'll finally upload demo of my Archipelago Mod!
BTW: But global variables are saved in savegames?
edited 1×, last 04.09.16 06:08:12 pm
var = variable [, description] [, default] [Global]
example1 variable $mfv:
var=mfv, my first variable,0,0
That variable is set to 0. Or $mfv=0.
example2 variable $msv:
var=msv, my second variable,5,0
That variable is set to 5. Or $msv=5.
_________________________________________________
If I want to change the variable in example1 from 0 to 12 I would use this:
setlocal "object",100,"mfv",12;
assuming the thing is an OBJECT with the ID = 100
_________________________________________________
If I wanted get the variable and use it in another script I would use a temporary variable to store it, then use that temp var:
$tmp=getlocal("object",100,"mfv");
so at that moment in my script $tmp would = 12
_________________________________________________
Sometimes you may need to get a variable, change it, then set the variable back. I have done this before but do not recall why atm.
1
2
3
2
3
$tmp=getlocal("object",100,"mfv"); $tmp2=$tmp+4; setlocal "object",100,"mfv",$tmp2;
so at that moment I have set the variable at that object to = 16
__________________________________________________
In summery above;
1) We simply set the variable from 0 to 12.
2) We simply got the variable to use it somewhere else...and it was 12 when we got it.
3) Lastly, we got the variable again, added 4 to it, and set it back again so it is 16
edit: Don't forget that if it is not an "object" to change that and the ID to "unit",id or "item",id etc...
edited 4×, last 25.09.16 09:46:47 pm
Global variables are global...meaning they can be accessed from anywhere. You can simply use the variable at any time, or any where in any script/s.
An example as to why you want to put it in the game.inf would be:
Say you want to keep track of how many units the player has killed. You would put a variable in the on:start as something like $units_killed=0; Then in every on:kill in the units.inf you might have $units_killed++; that adds +1 every kill.
So, now every time a new game is "started" the variable is set back to 0. Every time the game is saved/loaded the variable is saved and loaded keeping track of the killed units.
If you put it in the on:load every time the player loads a saved game it would be reset to 0...probably not what you want in this case.
edited 2×, last 27.09.16 02:15:41 pm
1