OR condition

For questions about using Classic.

Post » Mon Oct 04, 2010 9:19 am

I have never used OR and ELSE conditions in my projects. Usually I get runtime errors, but I think it is a waste of resources. So, here is an example, where I have insert an OR condition, but gives me a runtime error. What is wrong?

B
30
S
15
G
10
Posts: 285
Reputation: 7,144

Post » Mon Oct 04, 2010 9:38 am

Using OR will eventually cause problems that make your game crash. It is considered unstable and should be avoided imo. I only use OR very rarely and only in simple events without branching. And even then only for quickly testing stuff.

So instead of using OR you could just check if sCamera-isMoving + rLight-isMoving is greater than 0.

Oh, but don't be afraid to use the ELSE condition. That one is safe and very useful.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Oct 04, 2010 10:28 am

[quote:kgez78w6]So instead of using OR you could just check if sCamera-isMoving + rLight-isMoving is greater than 0.[/quote:kgez78w6]
Thanks, simple and clean solution :)
B
30
S
15
G
10
Posts: 285
Reputation: 7,144

Post » Mon Oct 04, 2010 11:03 am

ELSE condition looks that it does not work properly with sub-events inside.
B
30
S
15
G
10
Posts: 285
Reputation: 7,144

Post » Mon Oct 04, 2010 11:10 am

[quote="Aritz":18tz68ix]ELSE condition looks that it does not work properly with sub-events inside.[/quote:18tz68ix]
ELSE had issues until 0.99.91
Since then it works, at least for me.

[quote="PixelRebirth":18tz68ix]Using OR will eventually cause problems that make your game crash. It is considered unstable and should be avoided imo. I only use OR very rarely and only in simple events without branching. And even then only for quickly testing stuff.[/quote:18tz68ix]
Is this so? I couldn't read about it. Do you have a link or more info about what exactly is a problem with using OR? I for one do use it more and more, and had no issues so far. But I admit, I don't use it in overcomplicated structures. But I use it with branching also, and couldn't report any problems so far.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Oct 04, 2010 1:44 pm

I also had issues with OR. For ex.

If x greater or equal 1
or
if x lower or equal -1

It could work or not, it's really unstable. And when you have too much OR in one event. Later I've decided to change it on structure:

if xxx - then do xxx
else if xxy - do xxy
else if xyx - do xyx
else if...
and so on.
B
19
S
6
G
4
Posts: 171
Reputation: 2,507

Post » Mon Oct 04, 2010 2:02 pm

[quote="NugMan":198auk4v]I also had issues with OR. For ex.

If x greater or equal 1
or
if x lower or equal -1

It could work or not, it's really unstable. And when you have too much OR in one event. Later I've decided to change it on structure:

if xxx - then do xxx
else if xxy - do xxy
else if xyx - do xyx
else if...
and so on.[/quote:198auk4v]
I see, thank you. So it seems that OR'ed comparisons with numbers are working unreliable? I will test it. Would be very frustrating to debug if it happens to a progressed project. Thanks for the example!
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Oct 04, 2010 2:18 pm

[quote="tulamide":zhholzin]So it seems that OR'ed comparisons with numbers are working unreliable?[/quote:zhholzin]
I've got issues even with string comparsion, imo it's about OR in all cases - unstableness)
B
19
S
6
G
4
Posts: 171
Reputation: 2,507

Post » Mon Oct 04, 2010 7:28 pm

I've made a post about the possible problem with or:

[url:266zfgi9]http://www.scirra.com/forum/viewtopic.php?f=3&t=7428[/url:266zfgi9]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 05, 2010 12:57 am

Just thought that I'd point out a possible workaround to using the OR condition. I've found that most anything that I've wanted to use it for can be done just as well with the system condition Evaluate, using the OR operator in an expression form. Like so:

+ System: global('x') = 2 or global('x') = 5
-> Do something...

It has not caused me any problems, and allows for more complex logical tests in less space. Parentheses and the AND operator can be used to group parts of the expressions as appropriate, too. Perhaps something like so:

+ System: (global('x') = 2 and global('y') > 6) or (global('x') = 5 and global('y') <= 6)
-> Do something...

I've gone to this every time that the OR condition seemed to be causing me problems, and it worked.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests