How do I do an OR inside a while?

Just started using Construct 2? Post your questions here

Post » Tue Dec 01, 2015 7:22 pm

Basically I want a while block to continue if any of the two conditions are present. What I currently have is this:
Image

This does it so that I can make sure 1 wagon isn't the same as the one just before it, but I can't check for all three. If I turn the While into an OR block, it becomes While OR numwagon.AnimationFrame.... OR numwagon2.AnimationFrame. If I don't do it, it seems to treat it as an AND.

So how can I have an OR block INSIDE an While? Or is there some even simpler way to do this?
B
4
Posts: 8
Reputation: 216

Post » Tue Dec 01, 2015 8:15 pm

You could use a system->"pick by comparison"
with an expression like:
Code: Select all
numwagon.animationframe=numwagon2.animationframe | numwagon.animationframe=numwagon3.animationframe
B
85
S
27
G
85
Posts: 5,070
Reputation: 57,874

Post » Tue Dec 01, 2015 8:24 pm

R0J0hound wrote:You could use a system->"pick by comparison"
with an expression like:
Code: Select all
numwagon.animationframe=numwagon2.animationframe | numwagon.animationframe=numwagon3.animationframe

I'm not sure I'm understanding how "Pick by comparison" works. When I select it, I have to choose an object, expression, comparison and value. How do I do that with the code you've posted?
B
4
Posts: 8
Reputation: 216

Post » Tue Dec 01, 2015 8:40 pm

For doing it in event 2 of your pic...
the object would be numwagon2
The first expression would be: numwagon2.animationframe=numwagon.animationframe|numwagon2.animationframe=numwagon3.animationframe
The comparison would be "="
and the second expression would be 1
B
85
S
27
G
85
Posts: 5,070
Reputation: 57,874

Post » Tue Dec 01, 2015 8:54 pm

R0J0hound wrote:For doing it in event 2 of your pic...
the object would be numwagon2
The first expression would be: numwagon2.animationframe=numwagon.animationframe|numwagon2.animationframe=numwagon3.animationframe
The comparison would be "="
and the second expression would be 1

It works now, thanks!
Unfortunately, its now exposed another bug in my layout which I have to figure out. But at least now it is nicely random!
B
4
Posts: 8
Reputation: 216

Post » Thu Jan 05, 2017 4:44 pm

Hello everyone,
Sorry to dig this old topic, but my question is in the title... and it is unsolved as far as I'm concerned :/

R0j0's answer may be correct when the condition is related to an object, but what if it is related to a variable ?

Simple example :
- we are making a platformer
- we have two variables, one reflecting the left stick direction (LStick), the other stating if the player is crouched or not (IsCrouching)
- LStick can be set to "Up", "Down", "DownRight", "DownLeft"
- we want to set up a loop, instead of three redundant loops, that says :
while (LStick="Down" OR LStick="DownRight" OR LStick="DownLeft")
then IsCrouching= "True"


I've tried the "Pickbycomparison" but variables are not attached to an object so I don't know what to do...

Many, maaaany thanks in advance for the one who'll be able to answer me =)

(also, a quick side question : can you add an Else event after a While loop ? So that if the while loop is not working the IsCrouching is set to "False" again :?: )
Cheers
B
4
Posts: 2
Reputation: 213

Post » Thu Jan 05, 2017 5:17 pm

You don't want a loop here anyway, just an If:
if(LStick="Down" | LStick="DownRight" | LStick="DownLeft") -> IsCrouching= "True" Else IsCrouching= "False"

In C2, use Compare two values:
First value: LStick="Down" | LStick="DownRight" | LStick="DownLeft"
Comparison: Equal to
Second value: 1
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Post » Thu Jan 05, 2017 6:00 pm

If you want to keep it a bit more elegant you can use the "If is true" condition from TR_System plugin.

Image

You can do advanced logical operations there.
Image
B
28
S
15
G
54
Posts: 854
Reputation: 31,237

Post » Fri Feb 17, 2017 4:48 pm

Damn, I realized I forgot to thank you guys for your answers. Sorry. :?
Thanks to your help, I realized the while loop was totally optional in my case.
B
4
Posts: 2
Reputation: 213

Post » Sat Feb 18, 2017 1:04 pm

As you already digged up this topic, I'd like to mention that there's a new TR_System condition Is value in set which makes such things even easier.

Image
Image
B
28
S
15
G
54
Posts: 854
Reputation: 31,237


Return to Beginner's Questions

Who is online

Users browsing this forum: wehehe and 0 guests