Page 1 of 1
SetScore question
Posted: Sat Nov 30, 2019 1:57 pm
by Gunner98
This is a simple one but I'm just getting back into Lua and am drawing a blank. Trying to reset a score to '0'
a=ScenEdit_GetScore("Marker")
ScenEdit_SetScore("Marker", (a=0))
Getting: ERROR: [string "Console"]:2: ')' expected near '='
I've tried it a half dozen ways and there is a variation on this.
There may also be an error in the documentation at commandlua.github.io/
Shouldn't the example read ScenEdit_
SetScore...
I've tried it with just this line as well, no luck.
Thanks in advance

RE: SetScore question
Posted: Sat Nov 30, 2019 4:12 pm
by Whicker
ScenEdit_SetScore("Marker", 0)
no need to set it to a variable with the a= bit.
If you were retrieving the score then setting it = to a variable would make it so you could do stuff with it. But to just set it to zero there is no need for that.
Yes, the docs examples is not correct.
RE: SetScore question
Posted: Wed Dec 04, 2019 7:53 am
by Gunner98
Thanks Whicker
EDIT: OK sorted that out - when I string two commands together though I get another error
ScenEdit_SetScore("Marker", 0)
ScenEdit_SetScore("Marker 2", 0)
ERROR: [string "Console"]:2: unexpected symbol near ''No reason given''
Is there something I need to put between the two? Didn't think so..
Tx
RE: SetScore question
Posted: Wed Dec 04, 2019 10:51 pm
by Whicker
hmm, not sure. You should not need anything else. Does the second one work by itself? I would re-write it and see if that works, if you copy + paste sometimes you pick up illegal characters.
RE: SetScore question
Posted: Thu Dec 05, 2019 9:43 pm
by Gunner98
Yeah that's what I thought but strangely alone they work, together they don't. I can work around it - thanks for the help.
B
RE: SetScore question
Posted: Fri Dec 06, 2019 2:01 am
by Whicker
hmm, seems like anything you do after the first SetScore results in an error. There is a 3rd argument that function accepts for the reason, I think it is optional but don't see anything expressly saying that. But it does the same thing with a reason.
It seems like it may work ok even with the error but I am not positive - I ran a quick test scen and it seemed to work, in the game.
RE: SetScore question
Posted: Sun Dec 08, 2019 12:11 am
by michaelm75au
Reason is required for the Score log to work properly
RE: SetScore question
Posted: Sun Dec 08, 2019 12:38 am
by michaelm75au
There is code to handle the backward compatibility for no reason, but there is a bug in that.
RE: SetScore question
Posted: Sun Dec 08, 2019 1:27 am
by michaelm75au
ORIGINAL: Whicker
hmm, seems like anything you do after the first SetScore results in an error. There is a 3rd argument that function accepts for the reason, I think it is optional but don't see anything expressly saying that. But it does the same thing with a reason.
It seems like it may work ok even with the error but I am not positive - I ran a quick test scen and it seemed to work, in the game.
Current code only works for SetScore() as the only command in the Lua script. Removing the backward comparability fixes it; it will still handle the case of 'no reason' given for the score change.