Conditions not met, actions still happen

0 favourites
  • 12 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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.

    <img src="http://i44.tinypic.com/27ymh5.jpg" border="0" />

    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!

  • 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?!?!?!?!

  • 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)

  • 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.

  • 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!

  • 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.

  • 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.

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • All that is happening here is that the number is added so fast that it is registering your condition 4 by the time you have lifted your finger from the mouse...

  • Easier still add the number "on mouse Button released" instead of on clicked...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)