The or condition

0 favourites
  • So I wanted to discuss the or condition and the way it works. I think the way it's currently working has the same sort of problem the on collision condition used to have - it's inconsistent. For example:

    If right arrow is down

    or

    If D is down

    • set sprite x to sprite.x+1

    This could be handy for having both wasd and the arrow keys control a player, but if you hold right and D down at the same time, it doubles the speed of the sprite.

    Sure, you could have another event limiting the speed or something, but that would be another event, which defeats the purpose of the or block. There might as well be a second event for if D is pressed and the right arrow isn't pressed.

    I think instead of the way it works currently, it should be an additive selection list.

    If sprite x is > 100

    or

    If sprite y is > 100

    • rotate sprite

    In this example, what I think should happen is construct should check which ones x position is greater than 100, then check which ones y position is greater than 100 and add those instances to the selected list, then run the actions once on the combined list, rotating all of the selected sprites once.

    The way it currently is seems inconsistent - the number of times the actions will be run depends on the number of conditions that return true. What if you wanted to toggle a flag with an or condition? Then depending on the number of conditions that return true, it might get toggled twice.

    Also, it would be nice if the or condition was more of a traditional condition that could be dragged and dropped so that multiple conditions could be checked between an or.

    If sprite x is > 100

    If sprite variable = 1

    or

    If sprite y is > 100

    If sprite variable = 2

    • rotate sprite

    It would allow more control this way.

  • Wow, if it's running things twice, it's definitely a bug! Otherwise, what's the point? We'd just copy the events and switch around the conditions!

  • Arima,

    correct me if i'm wrong because i am definitely not a c2 expert...lol, but in your first example, i think the or condition works correctly. you just did not specify all the possible conditions for the outcome.

    what i mean is; you have a condition for if you press d, you have one for if you press the right arrow. so if you press them both together, the condition is doing exactly what you 'told' it to do. it is counting both conditions as true, because you have not given it an action to perform for pressing both. so if you simply add...

    If right arrow is down

    or

    If D is down

    or

    if D and right arrow are both down

    • set sprite x to sprite.x+1

    wouldn't that work correctly?

  • I agree with Arima that the OR condition is not supposed to work like this.

    The Action part should be executed only ONCE (when the whole condition is fulfilled/TRUE),

    instead of running the action as many times as the condition is true (like right now)

    Here is a simple example to play around, try to change the variable myNumber with different value to see different result:

    <img src="http://i43.tinypic.com/2m7ydk9.jpg" border="0">

    capx:

    http://dl.dropbox.com/u/39382262/OrSimple.capx

    myNumber: 1    Result: 2, 3, 4, 5

    myNumber: 2    Result: 3, 4, 5

    myNumber: 3    Result: 4, 5

    myNumber: 4    Result: 5

    Turning the action into sub-event doesn't really work either:

    <img src="http://i41.tinypic.com/2chmbth.jpg" border="0">

    capx:

    http://dl.dropbox.com/u/39382262/OrSubEvent.capx

    The weird thing is, on this case when myNumber is 1, it only executed once:

    myNumber: 1    Result: 2

    myNumber: 2    Result: 3, 4, 5

    myNumber: 3    Result: 4, 5

    myNumber: 4    Result: 5

    I submit this also as a bug here:

    http://www.scirra.com/forum/topic51183_post322670.html#322670

  • I think you should use the else condition instead. Here I made simple example: http://dl.dropbox.com/u/53898431/Junk/else_example.capx

    I think the or is working correctly, only one time it started to jump around and escape from my C2 and that's a bug.

    I see the or condition as if I would drink dirty water from a blue glass I would get stomack problems or if I would drink dirty water from a yellow glass I would still get my stomack problem. Now if I drink both glasses blue and yellow I would get my stomack problems twice as bad. This was to refer the double speed issue Arima mentioned.

  • Arima nemo Potato

    i believe i see what arima is talking about now, and i think i agree with him. in a normal programming paradigm;

    If right arrow is down

    or

    If D is down

    • set sprite x to sprite.x+1

    should only execute once if either condition is true.

    nemo, your example is slightly inaccurate to what arima is trying to say. your example expresses 'how much' you would get sick from drinking either glass of dirty water, but arima is simply stating this...

    If you drink dirty blue glass water

    or

    If you drink dirty yellow glass water

    • you will get sick

    how much you drink is not important in this logic condition. only whether you will get sick.

    i think arima is saying that the event should only execute once in the event of any or all conditions being true. which is the way it is 'interpreted' in programming logic. if you desire an event to execute with true conditions than you can design the events to do that, but by default...they should not.

    am i correctly understanding you now Arima?

    after answering you the first time, i read ash's explanation of how or works, and he explains that multiple true conditions will execute multiple event assessments.

    substituting and else condition would require double eventing...

    If right arrow is down

    • set sprite x to sprite.x+1

    else

    If D is down

    • set sprite x to sprite.x+1

    which is counter-intuitive to what the purpose of 'or' is for; to enable the user to connect several varied conditions to the firing of one event set, upon the true value of one, or more or even all of the conditions.

    i hope this was clearly explained. i don't want to make arima's point worse, by confusing people about his intent.

    and i apologize arima, for not reading thoroughly enough before trying to answer your post. like i said, i'm no c2 expert...lol. but i do agree with your assertion...now that i actually understand it.

  • well i have thoroughly confused myself now...lol.

    i can't tell, logically, which way is right or wrong. my brain says, if i want to increase a variable by 1, if either or all logic conditions are met than i should be able to. but every time i look at the examples that you all have given, something goes wonky in my head.

    tell me if this example correctly applies;

    -i have ten empty mail boxes.

    -i want to know how many times a day, with hourly intervals, the mail is delivered.

    -so i don't care how much mail is delivered into how many boxes, only that is has been delivered

    -if i set up all my mail boxes in an or condition saying something like

    if mailbox_1-10 is not empty this hour

    • then add 1 to 'delivered'

    with that set up, i want every hour for 'delivered' to be incremented once, if any or all mailboxes have been filled. but i think, it will be incremented by the number of mailboxes which have been filled in one hourly interval.

    does this make sense, or am i making this way harder than it should be?

    i think i am going to shut up now and wait for people far smarter than me to sort this out...lol.

  • harrio, in that case I think would be more appropriate to use a For each instead of Or:

    +For each mailbox

    +mail box is not empty

    add 1 to delivered

    I also agree with Arima that Or events should run only once per tick, otherwise things gets confusing.

    I can envision lots of people loosing hair because of variables acting strange an being incremented in an unexpected way in case the Or remains the way it currently is.

  • harrio - I think you're overcomplicating it a bit. The way it works now:

    Imagine there are two instances of a sprite. One has a variable=1, the other variable=2.

    If sprite variable=1

    or

    If sprite variable=2

    • rotate sprite 1 degree

    In this case, every tick, both instances would rotate 2 degrees. Add a third instance and a third condition:

    If sprite variable=1

    or

    If sprite variable=2

    or

    If sprite variable=3

    • rotate sprite 1 degree

    ...and the sprites will rotate 3 degrees, because the actions are run 3 times.

    Not only is the or condition not currently separating the objects from one condition to the next (why would the one with variable=1 rotate 3 times anyway? It seems the instances are being added together the way I think it should work as described below, and then the actions are running 3 times for no reason at all then? I'm a bit confused as well), I don't understand why the actions should run multiple times either.

    In the first example in this post, I think condition 1 should pick the instance with variable=1, then condition 2 should add the instance with variable=2 to the selected instances, and then run the actions once on the selected objects.

    Also, you can't currently have multiple conditions between ors, which is why I suggested or should be a normal condition above.

    harrio, in regards to what you suggested above, it's currently one condition only between each or, so this:

    If right arrow is down

    or

    If D is down

    or

    if D and right arrow are both down

    - set sprite x to sprite.x+1

    ...wouldn't work. Not to mention the sprite would move 3 pixels because all three sets of conditions would be true. You just showed what I mean about what's intended - for the sprite to move 1 pixel if any of the conditions are met!

    Adding an Ashley to make sure this thread doesn't get missed.

  • i think that 'for each' will do what i was trying to avoid...

    -every hour

    -if any or all mail boxes are not empty

    > add 1 to delivered

    basically, if an hour passed and all the mailboxes were filled 'delivered' would equal one, because there had been one delivery for that hour interval. the next hour, if all were empty, 'delivered' still equaled one. the third hour, if only one mailbox was 'not empty' then 'delivered' would then equal two, because there had been two deliveries in three intervals.

    but the for each would make 'delivered' equal ten, if in the first hour, all the mailboxes were 'not empty'.

    was that clear?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Arima,

    i think i am really losing it...lol. i thought i read an example of a multiple 'or' condition statement, and a multiple 'or' trigger statement in this tutorial...

    http://www.scirra.com/tutorials/292/guide-to-construct-2s-advanced-event-features

    i may need medical help to sort this all out.

  • Notice there is only one condition between each or in those examples. You can't have:

    Sprite.x=1

    Sprite.y=2

    or

    sprite is visible

    If you try it, it will result in:

    Sprite.x=1

    or

    Sprite.y=2

    or

    sprite is visible

  • For example:

    If right arrow is down

    or

    If D is down

    - set sprite x to sprite.x+1

    I've tried that in Construct Classic and it works as it should. The sprite is moved 1px forward no matter if I press one or both keys at once. And in C2, as you said, it moves double speed, so it's definitely bug.

  • Well you're right, OR is kind of broken in my first implementation in r86. I was a bit naive with the implementation - if you make an event:

    A or B or C: do actions

    it pretty much gets run as three separate events:

    If A: do actions

    If B: do actions

    If C: do actions

    I think the examples in this thread have proven that's totally broken, since if more than one condition is true and you toggle something, it gets toggled straight back. Whoops! Or movements speed up, counters get too much added, etc.

    Luckily I've already changed it for the next build. There might still be bugs in the next release, but it's changed to only runs the actions once even if multiple conditions were true. So

    A or B or C: do actions

    will run once if at least one condition was true. It also properly handles picking, so:

    + Sprite X < 320

    • or -

    + Sprite Y < 240

    -> do something with Sprite

    will now correctly run the actions once with the picked objects being those instances which match either condition.

    r86 kind of had a lot of bugs with the new event features! 'Else' and 'While' both have some weird issues as well. I think I've fixed everything for the next build though. Thanks for the feedback though. It's lucky we've got the beta and stable releases sorted out, this is kind of what we expected - smoothing things out over a few beta releases then getting a stable update out which hopefully works as expected.

  • Fantastic! :) Thanks, Ashley! Any word on allowing multiple conditions between ors as well?

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