SRL Archive - Help and Support

While .. do or/and?


RISK

2012-01-14 09:23:33

I wish to make a while .. do loop to wait for the script to successfully cross an obstacle. But I am a little confused as to how this would work:

while (not(FindChatBoxText(Obstacle.ChatText, 8, clBlack)) or
(not(FindChatBoxText('adva', 8, clBlack))) and (IsMoving)) do
begin
end;

Does the 'and (IsMoving)' apply to both the previous 'nots'? Or does it apply to only the second one which is the level advancement text?

Thanks in advance for any help.

Brandon

2012-01-14 09:26:34

Compilers/Interpreters Read from Left to Right unless there is an = sign in which it evaluates the right side first.

To get around ambiguity you can always use brackets. But in this case I believe it does the Or and And first then OR's the result. It does Order of Operations.

Edit.. I was wrong. See here (reading from right to left):


var
a: Boolean;
b: Boolean;
c: Boolean;
d: Boolean;

begin
a:= (7 = 3) or (7 = 7) and (2 = 1);
b:= (7 = 3) or (7 = 7) and (2 = 2);
c:= (7 = 7) or (7 = 7) and (2 = 1);
d:= (7 = 7) or (7 = 7) and (2 = 2);
writeln(a);
writeln(b);
writeln(c);
writeln(d);
writeln((not(true) and (true) or (not(true)) and (true)));
end.
[Banana]
Compiled successfully in 32 ms.
False
True
True
True
False
Successfully executed.
[/Banana]

RISK

2012-01-14 09:35:12

Let me see if my half-asleep brain has been able to comprehend this.

My example will count only the first two together and then it will do the 'And'. So what I would need to do is:
while (not(FindChatBoxText(Obstacle.ChatText, 8, clBlack)) and (IsMoving)
or (not(FindChatBoxText('adva', 8, clBlack))) and (IsMoving) do
begin
end;

Thanks, by the way. I really appreciate the help. :)

Brandon

2012-01-14 09:39:40

From: RISK
Let me see if my half-asleep brain has been able to comprehend this.

My example will count only the first two together and then it will do the 'And'. So what I would need to do is:

Thanks, by the way. I really appreciate the help. :)


Check out the edited post. "AND" has a higher priority than "OR".. Or simba reads from right to left.

The result to yours is the last one where I assumed all of them returned correctly, then the result is false.

bg5

2012-01-14 11:18:04

Priority in Pascal:

not 1 Highest
* / div mod and shl shr 2
+ - or xor 3
= <> < <= > >= 4 Lowest

Richard

2012-01-14 12:01:34

From: beginner5
Priority in Pascal:

not 1 Highest
* / div mod and shl shr 2
+ - or xor 3
= <> < <= > >= 4 Lowest


It then goes left to right, no?

Brandon

2012-01-14 12:08:37

From: Richard
It then goes left to right, no?


Google says: All Pascal operators are left to right associative.