local variables - crashing if empty
Issue #20
resolved
I tried to make a local variable to count the numbers the player said something over a few days. I don't want it global to don't mess with other variable which may have the same name. But if I leave the variable empty (every time assigning 0 would always override the information) crashes the engine.
label Start
local $TimesSaid; //Crash
end
label Start
local $TimesSaid = 1; //No crash
end
I wanted to make something like
label AskForGunPoder
if(GetLoveLevel() > 5) then
GiveItem(289, 1);
else
local $TimesSaid;
if($TimesSaid == nil) then
$TimesSaid = 0;
end
$TimesSaid = $TimesSaid + 1;
if($TimesSaid < 5) then
say "Creeper" "I dont have any for you now";
else
say "Creeper" "Stop asking me!";
end
end
end
Comments (5)
-
-
reporter Oh I see... Is it possible to work around this problem or do I have to make the variable global ?
-
I wouldn't call it a problem but rather per design. That is how local variables work in most lexical scoped languages. So you indeed have to use a script-global variable for that.
-
reporter OK thank you.
-
- changed status to resolved
- Log in to comment
while this is indeed a bug, you have a logical error there.
This would always be true. There are no C like static locals in MTS.