Toggle state-based button

Get help using Construct 2

Post » Wed May 07, 2014 9:11 pm

Hi,
I want to have a button that changes a text variable based on its own state. Per default the variable is 0, button 1 sets the it to 1, button 2 sets value 2. Pressing a button the second time should reset the variable back to zero.
So I have two' System'>'Compare value' events to toggle the state, but they seem to overwrite one another in the same cylce, effectively setting and resetting the value in a single cycle.
Can someone point me to a working example of a two button setup that toggle a single variable?

Here's what mine looks like:
You do not have the required permissions to view the files attached to this post.
B
15
S
6
Posts: 236
Reputation: 1,939

Post » Wed May 07, 2014 9:57 pm

looks like a big part of the problem is that I'm simultaneously providing touch and mouse controls, and while mouse alone can be set to work fine, my touch input seems to constantly trigger as well, despite not being on a touch device ...
B
15
S
6
Posts: 236
Reputation: 1,939

Post » Wed May 07, 2014 10:02 pm

Set the second condition in each sub event to an else condition. The way you have it set right now, the sub events trigger consecutively meaning, as soon as you set the value"nuke" and "spawn", the second condition is always true.

Just to be clear, the 2 conditions "Commander.controlmode = 'nuke'" and "Commander.controlmode = 'spawn'" should be changed so it is just an Else event. This means when the condition before it is not true this condition is true.
Last edited by FragFather on Wed May 07, 2014 10:11 pm, edited 1 time in total.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Wed May 07, 2014 10:09 pm

Also, you can combine your click and touch events by placing them in an or block. This will cut down the total number of events you will use by half.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Thu May 08, 2014 6:30 pm

I've been trying these things, among others, but the results are variations of what I described:

when holding the 'spawn' button it flickers, being set on and off
toggleSpawn_FlickersWhenHolding.PNG



when releasing the 'nuke' it immediately resets
toggleNuke_ResetsOnRelease.PNG



my real problem i believe is that all the 'On Touch ...' events trigger every cycle during mouse-clicking. which i find mildly disturbing.
Can I disable touch input when not on a touch device?
Is there a way to not register onTouch multiple times?
You do not have the required permissions to view the files attached to this post.
B
15
S
6
Posts: 236
Reputation: 1,939

Post » Thu May 08, 2014 6:56 pm

Set the touch object to count mouse clicks and remove the mouse click condition unless you need to test for right click.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Thu May 08, 2014 7:32 pm

good call, thanks
B
15
S
6
Posts: 236
Reputation: 1,939


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests