[Soved for x]One Button Switch between 3 or 4 items

Just started using Construct 2? Post your questions here

Post » Mon Aug 15, 2016 8:12 am

I want something to switch my images like switching themes, but I want only one button to cycle through choices.
Ive got

global
var frame = 0;
System.start of Layout
color1 set animation speed to 0
then
On button clicked
color1 set animation frame to 1
//subevent
System/frame=1 color set animation frame to 2
System/frame=2 color set animation frame to 3
System/frame=3 color set animation frame to 4

It doesn't really work. It goes from 0,1,4, instead of 0,1,2,3,4

maybe I need an array?
Thanks Anyone.
Last edited by DeathSpecter9 on Sun Aug 28, 2016 2:07 am, edited 3 times in total.
B
30
S
13
G
1
Posts: 41
Reputation: 2,933

Post » Mon Aug 15, 2016 3:47 pm

Need to use 'else'.
Right now 'set to 1' makes '= 1' true. If true it is 'set to 2' and that makes '=2' true. And so on.
B
33
S
18
G
27
Posts: 2,441
Reputation: 20,346

Post » Mon Aug 15, 2016 11:33 pm

Yes that makes a lot of sense thank you.
B
30
S
13
G
1
Posts: 41
Reputation: 2,933

Post » Mon Aug 15, 2016 11:57 pm

Yep That's what I needed thanks again.
Image
whoops I need one more. :lol: 8-) animation frame to 0 so it will loop back through the selections.
B
30
S
13
G
1
Posts: 41
Reputation: 2,933

Post » Fri Aug 26, 2016 3:32 am

What if I wanted to use 'set layer background color'
to this system choice loop thing.
Or css style or anything other than animation frames?
B
30
S
13
G
1
Posts: 41
Reputation: 2,933

Post » Fri Aug 26, 2016 9:00 am

Then you just do, as long as you do not need to pick instances any action will be fine.
B
33
S
18
G
27
Posts: 2,441
Reputation: 20,346

Post » Fri Aug 26, 2016 4:38 pm

As long as your numbers are in order, you can also use an incrementing value, like so:

Button On Clicked
AnimationFrame < 4 - Set Animation Frame to Animation Frame+1
Else - Set Animation Frame to 0

Or to be extra compact, you can use a conditional operator (advanced):
On Clicked - Set Animation Frame to Sprite.AnimationFrame<4?Sprite.AnimationFrame+1:0
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Fri Aug 26, 2016 7:51 pm

Well I went from using a sprite, to just changing the background color for now, and adding some .css to it instead of images.
Seems better on performance?

You guys got me thinking though.
*I keep forgetting to set instance variables.
But I don't think you can set one for "background" so I probably go back to images.
Thanks Guys.
B
30
S
13
G
1
Posts: 41
Reputation: 2,933


Return to Beginner's Questions

Who is online

Users browsing this forum: davidbox and 2 guests