OR, IF, ELSEIF, ELSE, WHILE, etc

Get help using Construct 2

Post » Tue Nov 01, 2011 4:47 pm

I like the logic behind the codes very much =D

And figuring out some conditions, I think the best way to achieve them is using these conditionals: OR, IF, ELSEIF, ELSE, WHILE.

Browsing today, one of the forum topics (Branch) did a workaround for some of them, but, I would like know if it's something I'm missing or they aren't in the events to be selected and used as well?

If they aren't used in the standard, I believe the best thing is avoid workarounds and keep my logics to make the same things =]

About the OR, that's something I mean is automatic, because if one of the conditions is not meat, the software will go to the next, the problem is when you want test one first and them the next one ^^TELLES08082011-11-01 16:51:21
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,192
Reputation: 18,301

Post » Tue Nov 01, 2011 10:08 pm

Adding an "if" condition is unnecessary as all conditions imply an "if".

"else" would be nice to have as Construct Classic has it, but it can be simply done with inverted conditions.

Which is what the branch plugin does, but if you want if/else to work with picking the you'll have to resort to events:


"or" can be done like traditional programming by using a local variable:

Or if you want to use "or" with picking:


"while" isn't really necessary as we already have the looping conditions "for" and "repeat". R0J0hound2011-11-01 22:09:42
B
79
S
24
G
53
Posts: 4,732
Reputation: 40,227

Post » Tue Nov 01, 2011 10:53 pm

Very nice explanation, thanks @Rojo
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,192
Reputation: 18,301

Post » Sat Nov 12, 2011 10:03 pm

I am having problems with doing an Else. I want to toggle my layouts back and forth.

http://dl.dropbox.com/u/49284765/Else%20Change%20Layout.capx
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Sat Nov 12, 2011 10:28 pm

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sun Nov 13, 2011 1:09 am

you rock Kyatric
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Wed Jan 25, 2012 5:23 pm

quick question, I have a button that toggles visibility of an object, in events:

on touch end
-- object is visible?
++++ make object invisible
-- object is invisible?
++++ make object visible

this of course loops itself through fully, because the object will be hidden by the first subevent and shown by second one. how to avoid this so it kinda breaks after making it invisible?
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Wed Jan 25, 2012 5:34 pm

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Wed Jan 25, 2012 5:40 pm

[QUOTE=Kyatric] @ranma: capx

?: is a conditional operator, which allows you to test conditions in expressions. [/QUOTE]
i know, but how do you use it with visibility and others. thanks for the response, but this does not apply, or at least i don't know how to use this operator with "make visible / invisible". also I need to retain this event structure, as this is a simplified version of my real problem.
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Wed Jan 25, 2012 5:47 pm

@ranma: dld again the previous capx.
I cheated using opacity.
It is a good question though, using the visible property with a conditionnal operator.
I'm not sure it can be done. If it can, I'd love to know how to.

For that one though, there's a trick/workaround to use a temp variable.
The code you first gave would look like :

[code]on touch end
-- object is visible?
-- tVar = 0
++++ make object invisible
++++ tVar = 1
-- object is invisible?
-- tvar = 0
++++ make object visible
++++ tVar = 1
[/code]

This stops the "looping" effect.Kyatric2012-01-25 17:49:13
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Artpunk, indiegrimes, NRABrazil, PixelatedTrip and 26 guests