Conditions not met, actions still happen

Get help using Construct 2

Post » Fri Jun 21, 2013 6:05 pm

Okay, this is incredibly frustrating and there's no way my code or conditions are wrong so I'm beginning to think Construct 2 is bugged.

Here is a screenshot of part of my code.


The FIRST time a button is clicked, it adds +1 to the integer value in the dictionary.

The SECOND time its clicked, its supposed to run actions at the bottom (which I've deleted out to save time and space.)

Unfortunately, the first time the button is clicked, it runs all of those actions, completely disregarding the condition that ButtonClick MUST = 1.

In other words, ButtonOkClick becomes 2 with just one click of the button, which is not what I coded, and not what I see on the screen. Solutions?

Thanks in advance!
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Jun 21, 2013 6:06 pm

Also, when I add the event "Button on clicked" and then look at it again, it immediately treats it like a condition... what program changes events to conditions and gets away with it?!?!?!?!
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Jun 21, 2013 6:12 pm

I'm pretty sure it's because when you click the button and it's 0, event 3 will be true so it adds 1 to ButtonOkClick. Then, since ButtonOkClick == 1, when it gets to event 4 the conditions will be true also. Try flipping them around (Event 3 becomes event 4, event 4 becomes event 3)
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Fri Jun 21, 2013 6:15 pm

But it is doing what you told it to do. You just added 1 to ButtonOKClick, so when it hits event 4, the condition is true! Change it to have one On clicked event, then use subevents with ELSE to make sure you are only running one condition at a time.
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Fri Jun 21, 2013 6:48 pm

I want the conditions on Event 4 to be true, but I want it to wait until I hit "okay" a second time. What's the point in having a button "on-click" event otherwise? Right now, in Event 4, "on-clicked" plays absolutely no role in the code!
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Jun 21, 2013 7:05 pm

Use a single condition "On clicked" and then, as subevent, test the value of your dictionary and don't forget to add a "Else" system condition.

It's not a bug in C2, it's something beginners are often overlooking.
Once you get the hang of it, it makes perfect sense.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,311
Reputation: 71,086

Post » Fri Jun 21, 2013 7:05 pm

C2 runs all events top to bottom. If you have multiple events with the 'object clicked' condition, those will both be run immediately one after another. So what happens is this:

User clicks object

C2 halts processing the rest of the event sheet and immediately runs mouse clicked trigger events
Event 3 is run - buttonokclicked=0, C2 sets it to 1.
Event 4 is run immediately after - buttonokclicked=1 (as it was set to 1 in the event preceeding it), so event 4's actions are run, setting buttonokclicked to 2.

What you need to do is either of the two things suggested to you:

On clicked object
(Subevent) if buttonokclicked=1, set buttonokclicked to 2
(Subevent) if buttonokclicked=0, set buttonokclicked to 1

Or

On clicked object
(Subevent) if buttonokclicked=0, set buttonokclicked to 1
(Subevent) else/if buttonokclicked=1, set buttonokclicked to 2

Either of those should work.Arima2013-06-21 19:07:15
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Fri Jun 21, 2013 7:56 pm

Hi all,

Thanks a lot for the help, although I don't think my problem is solved. I might not have been clear in my issue. I now understand the way Construct 2 reads events/actions, but I'm still at a loss for a solution.

The FIRST time I click "okay" I want X things to happen. The SECOND time I click "okay" I want Y things to happen. I tried to solve this by creating an integer value (or an instance variable) that would keep track of the # of times the button was clicked. I tried to say "The first time its clicked, do this, add 1 to #times clicked." Then I wanted to have a code that waits until the second time the button is clicked. I tried to do this by creating a separate event "Button on-click" and adding the condition "#timesclicked = 1." I'm beginning to think I need to make a new button that also says, "okay" just so this program can differentiate between them... that way I can say when "Okay1" is clicked do Y.

I'm definitely not having problems adding or setting integers...

Thanks!

Edit: I also don't see a Wait for Condition option... otherwise I could wait until someone touches the button?ClocksTNW2013-06-21 20:01:50
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Jun 21, 2013 8:35 pm

ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Fri Jun 21, 2013 8:49 pm

Make a variable called "clickDelay", and then add an event like this:

"clickDelay" > 0
-> Subtract 1 from "clickDelay"

Now add an action to both those events you have:
-> Set "clickDelay" to 6

And a condition to both your events:
"clickDelay" <= 0

Now you will never fire click events twice by accident, it will have a 1/10 of a second of time between clicks
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests