OR, IF, ELSEIF, ELSE, WHILE, etc

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  12>
Author
7,889 Rep
Post Options Post Options   Quote ranma Quote  Post ReplyReply Direct Link To This Post Topic: OR, IF, ELSEIF, ELSE, WHILE, etc
    Posted: 25 Jan 2012 at 6:03pm
Originally posted by Kyatric Kyatric wrote:

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

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


This stops the "looping" effect.


great, here's the exact code that worked, has to be inside a group as local variables can only be applied inside groups:


-----------------
group: clicking
-----------------
local number clickloop = 0

on touch end: clickloop = 0
-- object is visible?
-- clickloop == 0?
++++ make object invisible
++++ set clickloop = 1
-- object is NOT visible?
-- clickloop == 0?
++++ make object visible
++++ set clickloop = 1


hope it helps someone, thanks Kyatric
Back to Top

Moderator
29,640 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jan 2012 at 5:47pm
@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 :

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


This stops the "looping" effect.

Edited by Kyatric - 25 Jan 2012 at 5:49pm
Back to Top
7,889 Rep
Post Options Post Options   Quote ranma Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jan 2012 at 5:40pm
Originally posted by Kyatric Kyatric wrote:

@ranma: capx

?: is a conditional operator, which allows you to test conditions in expressions.

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.
Back to Top

Moderator
29,640 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jan 2012 at 5:34pm
Back to Top
7,889 Rep
Post Options Post Options   Quote ranma Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jan 2012 at 5:23pm
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?
Back to Top
4,877 Rep
Post Options Post Options   Quote Guyon Quote  Post ReplyReply Direct Link To This Post Posted: 13 Nov 2011 at 1:09am
you rock Kyatric
Back to Top

Moderator
29,640 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 12 Nov 2011 at 10:28pm
Back to Top
4,877 Rep
Post Options Post Options   Quote Guyon Quote  Post ReplyReply Direct Link To This Post Posted: 12 Nov 2011 at 10:03pm
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
Back to Top
9,953 Rep
Post Options Post Options   Quote TELLES0808 Quote  Post ReplyReply Direct Link To This Post Posted: 01 Nov 2011 at 10:53pm
Very nice explanation, thanks @Rojo
Back to Top
7,061 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 01 Nov 2011 at 10:08pm
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".

Edited by R0J0hound - 01 Nov 2011 at 10:09pm
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down