How do I add value to variable?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • 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"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • ultrafop

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

    gyazo.com/8c7b830a981693ee8cafc55bd43412a2

  • 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)

    Oops, just noticed, I included 4 instead of resetting on 4, just leave the 4 out of the Tokenat.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)