Make games! Discuss those games here.
Moderators: Bob the Hamster , marionline , SDHawk
marionline
Metal Slime
Posts: 673 Joined: Sat Feb 26, 2011 9:23 pm
Post
by marionline » Wed Aug 07, 2013 1:01 pm
Hi,
It feels a bit stupid to ask such a thing, but even thoug using the plotscript dictionary I fail to figure out how to increase a (global) variable.
The compiler tells me that + is not allwed inside a script, and suggested using add, but still the script is not acepted.
I placed the variable under the include part, I hope that's okay.
Code: Select all
global variable (1,stepcounter)
...
plotscript,each step,begin
# global variable can be read and set in any script
stepcounter add 1
show value (stepcounter)
end
Thanks for you help!
BMR
Metal King Slime
Posts: 3310 Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:
Post
by BMR » Wed Aug 07, 2013 1:49 pm
Code: Select all
plotscript, each step, begin
stepcounter += 1
end
That's pretty much it I suppose. Alternatively:
Code: Select all
plotscript, each step, begin
stepcounter := stepcounter + 1
end
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Bob the Hamster
Liquid Metal King Slime
Posts: 7460 Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:
Post
by Bob the Hamster » Wed Aug 07, 2013 2:12 pm
marionline wrote: Hi,
The compiler tells me that + is not allwed inside a script, and suggested using add, but still the script is not acepted.
Can you send me a screenshot or a copy-paste of that error message? it sounds wrong.
Gizmog
Metal King Slime
Posts: 2614 Joined: Tue Feb 19, 2008 5:41 am
Post
by Gizmog » Wed Aug 07, 2013 4:37 pm
I think when you use the add command, you're supposed to seperate it from the numbers involved with commas. Like, shouldn't it look like:
Bob the Hamster
Liquid Metal King Slime
Posts: 7460 Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:
Post
by Bob the Hamster » Wed Aug 07, 2013 5:07 pm
I... I don't even remember if Giz is correct.
I think nobody should ever be using the add command directly. Any error message that still recommends it is a bug.
marionline
Metal Slime
Posts: 673 Joined: Sat Feb 26, 2011 9:23 pm
Post
by marionline » Wed Aug 07, 2013 5:12 pm
That's the Error message I got:
I re-read it and i think it's not saying that I should use add instead of +, so the problem here were a missunderstanding. Still, I'm not sure what the compiler wants to tell me. Sorry.
I'll try out the other sugesstions on how to increase a variable and I'll tell you what worked and what not, maybe we could then add an example to the
plotscript dictionary or the wiki.
TMC
Metal King Slime
Posts: 4101 Joined: Sun Apr 10, 2011 9:19 am
Post
by TMC » Wed Aug 07, 2013 5:50 pm
It's complaining that "stepcounter + 1" doesn't do anything. Yes, add two numbers together, and then what? The result of the addition is thrown away.
Yes, Giz is right. And trivia: if you don't include plotscr.hsd then you should instead write "add(a, b)"
marionline
Metal Slime
Posts: 673 Joined: Sat Feb 26, 2011 9:23 pm
Post
by marionline » Wed Aug 07, 2013 6:04 pm
@TMC: Now it makes sense. Thanks!
BMR's version works.
Giz's version seems not to work, the compiler says that 0 arguments are passed to math function add, but it should be always two.
Thanks!
TMC
Metal King Slime
Posts: 4101 Joined: Sun Apr 10, 2011 9:19 am
Post
by TMC » Wed Aug 07, 2013 6:29 pm
Oh whoops, Giz and I were wrong. I'm thinking of the mod command which has a different form when plotscr.hsd isn't included.