[SOLVED] How do I switch ON OFF button

Just started using Construct 2? Post your questions here

Post » Sun May 10, 2015 10:20 am

Dear friends,

i need to understand how C2 logic work
so, i create two object, one sprite ON and one sprite OFF
Image

now i go to write some "code": when i click on object ON, it becames invisible, so i can click on OFF and the sprite ON return to visible

Image

and this not working :shock:

but, if i toggle the second part for testing, the first part of "code" is fine

Image

so, where i wrong?
please help me
:)
Last edited by Agrauwin on Sat May 16, 2015 11:54 am, edited 1 time in total.
B
8
S
1
Posts: 17
Reputation: 503

Post » Sun May 10, 2015 11:57 am

Events are read from top to bottom..
after the actions of the first event is triggered, the conditions of the second event are true that same tick, so will be triggered also..
When the actions of both events are executed it looks like nothing has changed..

There are many ways to fix this.
One way to do it without changing to much of the way you have set it up, would be to put the On is not visible as a subevent and add an else event below.

- mouse on left button clicked on off
----- On is visible
> On set invisible
> Off set visible
------ else
> On set visible
> Off set invisible

Another way, which would have my preference, would be to use animationframes for on and off, toggling a boolean variable and setting the frame accordingly.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 11, 2015 9:42 pm

This is how i did it for my Game. I used a Variable to determine wether the light is on or off.

I would suggest making one sprite with two frames though.

Image
B
16
S
7
G
2
Posts: 111
Reputation: 2,149

Post » Tue May 12, 2015 12:23 am

This will do
Image
ImageImage
B
109
S
49
G
23
Posts: 783
Reputation: 22,636

Post » Tue May 12, 2015 12:28 am

Nice @alextro :D
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Tue May 12, 2015 2:14 pm

thanks to everybody, i will test soon... :)
B
8
S
1
Posts: 17
Reputation: 503

Post » Tue May 12, 2015 9:08 pm

With absolution, subtraction works too.
Image
ImageImage
B
109
S
49
G
23
Posts: 783
Reputation: 22,636

Post » Fri Sep 23, 2016 12:21 pm

thanks alextro! very usefull!
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Mon Jan 09, 2017 5:39 am

Here's how I got a "music on/music off" button to work:

Image
All your bases are belong to us.
B
21
S
13
G
4
Posts: 12
Reputation: 4,052


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests