Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Multiples OR

Author
Message
Lernox
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location:
Posted: 27th Jul 2017 18:16
Hi. I have a little problem with "or" when multiples vars is compared, so:

when i did :



its work and printed "Value not ok". Its ok!

but when i did :



its dont work. And work only if i did : if a =5 or b =5 or c=5 ... Can u help me? Thanks u very much =)

Sorry for my wierd englis, im french :p
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 27th Jul 2017 18:52 Edited at: 27th Jul 2017 18:54
If a then... Means "a=1" .

So you can't use the type of notation you try with AppGameKit you must be explicit (except for "=1")
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Lernox
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location:
Posted: 27th Jul 2017 19:18
Ok but...


if a = means if a = 1 ..... then b = 1 and c = 5 . Why Value OK is printed?

I cant understand
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 27th Jul 2017 20:02
AGK is a bit quirky due to lack of boolean type. It is integrated with the integer type, rather than being a proper type by itself.

So 0 and 1 can also be read as false and true respectively. Which can cause trouble with eval statements, such as in if, while and until. Infact, anything not 1 will be read as false unless you throw in an eval operator like =, < or >.

And there are more gotchas for new players. And/or operators concatenate evals. Think of each eval as a dimension. The more you throw in, the more complicated it gets.

Your first example reads as:

if <false> and <false> and <false>
// do stuff
else
// do something else
endif

Three false eval do not make a true eval, and since all three evals need be true for the if statement to return true, it'll do something else.

Your second example reads as:

if <false> or <false> or <true>
// do stuff
else
// do something else
endif

One of the evals return a true, so the if statement will read as a true and do stuff.

What you need do is have a proper eval on each variable (unless using as a pseudo-bool 0/1 variable naturally) - so your two examples should read:

if a = 5 and b = 5 and c =5
// do stuff
else
// do something else
endif

and

if a = 5 or b = 5 or c =5
// do stuff
else
// do something else
endif

Easier to read and reason over. In the first, all need equal 5, in the second any one need equal 5. Which is another thing to keep in mind - write code to make it easy to read. It may be a bit more verbose, and use a few more lines, but when you get back to it in a month or two you won't go "WTF?!" every two seconds reading it. Code quality is measured in "WTF?!" per minute - fewer is better.
Lernox
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location:
Posted: 27th Jul 2017 21:02
Haha ok, thanks dude.
If i understood i cant do
if a and b and c= .....
and i cant do
if a or b or c=.......
so im forced to specify each parameters like:
if a = 5 and b = 5 and c =5
or
if a = 5 or b = 5 or c =5
right?
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 28th Jul 2017 11:40
Yes, indeed.

Login to post a reply

Server time is: 2024-09-30 05:38:52
Your offset time is: 2024-09-30 05:38:52