Using one button and variable to switch states

Get help using Construct 2

Post » Fri Oct 12, 2012 11:41 am

Hi everyone,

I have a newbie issue that I hope someone can help me with.

In my game, I have two characters that the player swaps between (they're basically invisible and inactive when not in use). I want to have a single button that the player presses to change between them which checks which character is currently in use (either 1 or 0, stored in a global variable).

My game is currently in a bit of a mess but I've recreated the situation in a new file. I'm not yet permitted to post links but I hope that this will work: http://www.nag.co.za/lab/BlueTester.capx

Or this screenshot will hopefully make sense:


Thanks in advance :)
B
56
S
15
G
10
Posts: 910
Reputation: 11,952

Post » Fri Oct 12, 2012 12:03 pm

Here you go: BlueTester2.capx (r106)
ramones2012-10-12 14:53:48
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Oct 12, 2012 12:23 pm

Ah, brilliant. Thanks ramones, that makes perfect sense.
B
56
S
15
G
10
Posts: 910
Reputation: 11,952

Post » Fri Oct 12, 2012 2:18 pm

I'd suggest posting this to the bugs section, this looks like it could be an actual bug. I see no reason why the way you wanted to do it wouldn't work.

I messed around with it. Seems I can get it to respond to the click when the variable is equal to 0, but not otherwise.

Edit: I tried it with a boolean, and while it works with toggling the boolean, the problem seems to be precent when setting the boolean manually (makes sense since all the boolean is is a variable with only 0 and 1).

I would want to check ramones capx to see what he did, but it's not available it seems.inkBot2012-10-12 14:29:16
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Fri Oct 12, 2012 3:02 pm

Event 2 basically cancels out event 1. If 'isBlue = 1' when you click on the button, you'd think only event 1 would run. But the way I think it works is, when you click, it checks and runs each mouse click event one at a time. So event 1 runs and sets isBlue to 0. And then event 2 is true so it runs and sets isBlue back to 1.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Oct 12, 2012 4:26 pm

I exchanged the mouse clicks with simply pressing space, the problem persists.

Edit: Also tried with an actual button. Same thing.

Not sure what the issue is, but there is an issue. That much is clear.inkBot2012-10-12 16:37:34
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Fri Oct 12, 2012 4:58 pm

I don't think I explained it well. It doesn't matter if it's mouse/keyboard/button.

In this example you'll agree that var will be 0 every tick regardless of whether it starts as 1 or 0:



This is the same thing only when space is pressed:



var will always be 0 because if the first event makes it 1 then the second event will set it back to 0.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020


Return to How do I....?

Who is online

Users browsing this forum: BipolarMike, Televangelist, totoe and 20 guests