SetScore question

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
Gunner98
Posts: 5998
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

SetScore question

Post 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



Image
Attachments
SetScore.gif
SetScore.gif (19.55 KiB) Viewed 403 times
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: SetScore question

Post 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.
User avatar
Gunner98
Posts: 5998
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: SetScore question

Post 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
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: SetScore question

Post 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.
User avatar
Gunner98
Posts: 5998
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: SetScore question

Post 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
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: SetScore question

Post 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.
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: SetScore question

Post by michaelm75au »

Reason is required for the Score log to work properly
Michael
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: SetScore question

Post by michaelm75au »

There is code to handle the backward compatibility for no reason, but there is a bug in that.
Michael
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: SetScore question

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

Return to “Lua Legion”