How do I add value to variable?

Get help using Construct 2

Post » Wed Oct 28, 2015 12:44 am

How would you add different values to the same global variable?
Eg:
I click "button", and it adds 1 to "gVariable".
I click "button" a second time, it adds 2 to "gVariable".
I click "button" a third time, it adds 3 to "gVariable".
I click "button" a fourth time, it adds 1 to "gVariable".

Then it continues to loop by adding 1, then 2, then 3, then 1, then 2, etc...

Is this possible to do in as few events as possible? Rather than have many, many different events/functions and calling them?

Thanks in advance.
B
6
Posts: 40
Reputation: 336

Post » Wed Oct 28, 2015 1:25 am

My thinking is that you would have two variables here, an "add variable" and the "gVariable" you mentioned.

Set up something like,

1)
When button is clicked
sub event - if "add variable" = 3 set to 1
else - add 1 to "add variable"

2)
when button is clicked add "add variable" to "gvariable"
B
55
S
32
G
23
Posts: 333
Reputation: 16,616

Post » Wed Oct 28, 2015 3:21 am

So based on your example by the 4th click the gVariable would equal 7?

If instead it should be 1,2,3,1,2,3 and not 1,3,6,7 then you would use a on click compare event starting with 0.
On-click/compare gVar=0/set gVar 1, gVar=1 set 2, gVar=2 set 3, else gVar>2 set 1.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 636
Reputation: 9,333

Post » Wed Oct 28, 2015 5:38 pm

Message: Knovolt can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
@ultrafop
@chrisinfinger

Thanks for the input and ideas. But, with your help and a little changing around, I got this working.

https://gyazo.com/8c7b830a981693ee8cafc55bd43412a2
B
6
Posts: 40
Reputation: 336

Post » Wed Oct 28, 2015 6:21 pm

I took that as a challenge to make the shortest solution possible.
Can anyone go shorter? ;-)

here's mine: (button sprite has an instance variable, IVariable)

Image


Oops, just noticed, I included 4 instead of resetting on 4, just leave the 4 out of the Tokenat.
B
226
S
60
G
33
Posts: 902
Reputation: 39,989


Return to How do I....?

Who is online

Users browsing this forum: NN81, TsubaRu and 9 guests