How do I - If Then Else

Get help using Construct 2

Post » Sat Feb 07, 2015 12:36 am

Image

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?
Last edited by blackcrypt on Sat Feb 07, 2015 12:44 am, edited 1 time in total.
Image
B
14
S
3
G
1
Posts: 61
Reputation: 1,003

Post » Sat Feb 07, 2015 12:39 am

The "Else" goes directly under event 11, not as a sub-event.
B
223
S
59
G
32
Posts: 901
Reputation: 39,240

Post » Sat Feb 07, 2015 12:45 am

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

Image
Image
B
14
S
3
G
1
Posts: 61
Reputation: 1,003

Post » Sat Feb 07, 2015 12:50 am

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
B
32
S
8
G
2
Posts: 100
Reputation: 2,610

Post » Sat Feb 07, 2015 1:01 am

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.
Image
B
14
S
3
G
1
Posts: 61
Reputation: 1,003

Post » Sat Feb 07, 2015 1:06 am

I think from what I understand keyboard are trigger events so ELSE does not work with it. Which is stated in the Manual
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.
Last edited by PhoenixNightly on Sat Feb 07, 2015 1:14 am, edited 1 time in total.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Sat Feb 07, 2015 1:13 am

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

@PhoenixNightly
Trigger events can not be inverted.
You do not have the required permissions to view the files attached to this post.
B
32
S
8
G
2
Posts: 100
Reputation: 2,610

Post » Sat Feb 07, 2015 1:15 am

+1 thatserafimkid
Yea wasn't sure on the inversion. I am better when I have it up in front of me :D
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Sat Feb 07, 2015 1:24 am

PhoenixNightly wrote:+1 thatserafimkid
Yea wasn't sure on the inversion. I am better when I have it up in front of me :D


Aha no worries. Same with me. I just happen to be at my computer ready to test.
B
32
S
8
G
2
Posts: 100
Reputation: 2,610

Post » Sat Feb 07, 2015 1:50 am

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 :lol:

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.

Image

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).
Image
B
14
S
3
G
1
Posts: 61
Reputation: 1,003

Next

Return to How do I....?

Who is online

Users browsing this forum: emreyigit03, plinkie and 4 guests