OR, IF, ELSEIF, ELSE, WHILE, etc

0 favourites
  • 11 posts
  • 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 ^^

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    <img src="http://dl.dropbox.com/u/5426011/pics/ifelse2.png" border="0" />

    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:

    <img src="http://dl.dropbox.com/u/5426011/pics/ifelse1.png" border="0" />

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

    <img src="http://dl.dropbox.com/u/5426011/pics/or.png" border="0" />

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

    <img src="http://dl.dropbox.com/u/5426011/pics/or_with_picking.png" border="0" />

    "while" isn't really necessary as we already have the looping conditions "for" and "repeat".

  • Very nice explanation, thanks Rojo

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

    dl.dropbox.com/u/49284765/Else%20Change%20Layout.capx

  • you rock Kyatric

  • 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?

  • 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.

  • 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.

  • 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

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