How to increase a variable with plotscript?

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

How to increase a variable with plotscript?

Post by marionline »

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! :D
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

Post by BMR »

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
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Re: How to increase a variable with plotscript?

Post by Bob the Hamster »

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.
User avatar
Gizmog
Metal King Slime
Posts: 2614
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

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:

Code: Select all

stepcounter,add,1
User avatar
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 »

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.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

That's the Error message I got:
Image

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. :angel:

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 »

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)"
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

@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! :D
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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