How do I - If Then Else

0 favourites
  • 14 posts
  • I can't get it to work. I read all the relevant stuff in the manual but the manual doesn't tell you how to achieve these things from a UI perspective - ie 'click this and drag it there'.

    I want to achieve :

    If left or right key is pressed set gravity to 0 ELSE set gravity to 5.

    I know that Else can't go there because it can't go under a triggered event, but how do I achieve this? How do I make the keyboard detect a non-triggered event?

  • The "Else" goes directly under event 11, not as a sub-event.

  • I get the same 'not valid here' if I put it under 11 (as event 12).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could set the gravity back to 5 on left or right arrow released trigger.

    Either that or depending on what you are doing with the arrow keys you could use Left arrow is down or right arrow is down instead of on pressed. You could add an else to the is down event

  • I will still have to test for the keyboard press which is a triggered event - the ELSE just is not logical there because it will never be run because that part of the code will ONLY be 'run' when a key is pressed, That's what the little green arrow means.

  • I think from what I understand keyboard are trigger events so ELSE does not work with it. Which is stated in the Manual

    [quote:263r4iks]

    Else

    Run if the previous event did not run. Note that this condition does not pick any objects: if it follows an event that picks objects, in the Else event all instances revert to picked again. Else can only follow normal (non-triggered) events. It can also follow another Else event with other conditions to make an "if - else if - else" chain.

    what you can do is switch to say:

    if Right Arrow is NOT Pressed AND Left Arrow is NOT Pressed set Gravity to 5 (which you right click the condition and say INVERT)

    So have a condition for if its pressed and another for if it isn't

    I am not at my personal computer it is more of a shot in the dark. But I think the top condition with the green makes it a trigger event.

    EDIT::

    Sorry was typing my response when you replied.

  • This is what I meant. You can test for when the arrow keys were released.

    PhoenixNightly

    Trigger events can not be inverted.

  • +1 thatserafimkid

    Yea wasn't sure on the inversion. I am better when I have it up in front of me

  • +1 thatserafimkid

    Yea wasn't sure on the inversion. I am better when I have it up in front of me

    Aha no worries. Same with me. I just happen to be at my computer ready to test.

  • Thanks for your answers, but I don't want to detect when a key was released - this would assume the key has been pressed already - also I think 'released' is a one shot test which will only trigger after the key has been pressed - acts as a kind of trap - the action will only occur after you lift your finger and not as soon as you press the key. The difference being that one way will act like autofire and the other would require continuous tapping of the key - I want the autofire behaviour - I care about the finger joints of my users

    I'm still searching for a way to implement the logic...

    If the player is pressing the left arrow - OR - the right arrow then set gravity to 0 - ELSE - set gravity to 5.

    Ok, I sussed out what the issue was - and it was the difference between Pressed and Down.

    When I used If key is pressed I get a little green arrow next to the event and I'm unable to place an Else event directly after it - I switched to Key is down and bam! I can pop the ELSE right in there.

    Can I just say thanks for taking the time to reply to my post, but I don't think adding extra events to solve a problem is the way forward especially as the issue was my lack of understanding of the event system (maybe just where pressed / down are concerned maybe).

  • If you are using it to set gravity to a constant number then you don't need to set it every tick. Key is down and else will run every tick. That's why I suggested using key pressed key released. that way gravity is only set once when true. You could have gravity at 5 default to start the game that way its already 5 before your user has to press and release a key. Then on key press it will change to 0.

  • You should do what I do now. Make a global variable for each key your game uses and when the appropriate key is down for each variable constantly add 1 to it until the button is released then put the variable back to 0. Then all you do is if you want to test if a key was only pressed and not held down, you check if the variable = 1. Anything greater than 0 and 1 is holding down the button.

  • blackcrypt try this demo

  • Thanks guys, but this already got fixed - see last entry on page one!

    But if you are in a helping frame of mind I have another topic that seems to be invisible to most forumgoers...

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