The or condition

Discussion and feedback on Construct 2

Post » Sun Apr 15, 2012 6:28 pm

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.Arima2012-04-15 18:29:26
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sun Apr 15, 2012 9:20 pm

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!
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Sun Apr 15, 2012 9:47 pm

@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?harrio2012-04-15 21:48:31
B
50
S
17
G
15
Posts: 1,029
Reputation: 26,289

Post » Sun Apr 15, 2012 10:34 pm

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:



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:


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#322670Potato2012-04-15 22:45:10
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Sun Apr 15, 2012 10:54 pm

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.nemo2012-04-15 23:00:31
B
40
S
5
G
5
Posts: 405
Reputation: 5,657

Post » Mon Apr 16, 2012 12:07 am

@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.
B
50
S
17
G
15
Posts: 1,029
Reputation: 26,289

Post » Mon Apr 16, 2012 12:23 am

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.
B
50
S
17
G
15
Posts: 1,029
Reputation: 26,289

Post » Mon Apr 16, 2012 12:55 am

@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.
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Mon Apr 16, 2012 1:14 am

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

[QUOTE=harrio]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[/QUOTE]

...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.Arima2012-04-16 01:33:31
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Mon Apr 16, 2012 1:19 am

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?
B
50
S
17
G
15
Posts: 1,029
Reputation: 26,289

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Colludium, Lof, Yahoo [Bot] and 12 guests