SRL Archive - RS3 Help

If Else not working for me.


nero_dante

2015-03-08 11:36:45

My 'if else' is not working on my script for some reaosn. Not sure why. If I take it out the script works fine.

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk Log Bea') then
fastClick(MOUSE_LEFT);
else begin
wait(500);
writeLn('Can not find Looking again');
terminateScript();
end;
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));

SlipperyPickle

2015-03-08 11:41:00

From: nero_dante
My 'if else' is not working on my script for some reaosn. Not sure why. If I take it out the script works fine.

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk Log Bea') then
fastClick(MOUSE_LEFT) //Here was the ';', remove this <------------
else begin
wait(500);
writeLn('Can not find Looking again');
terminateScript();
end;
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));


Remove the ';'. I believe it should work then.

nero_dante

2015-03-08 11:46:25

From: SlipperyPickle
Remove the ';'. I believe it should work then.


I tried that lol, still gives this error

'Error: Found unexpected token "else", expected "End" at line 37
Compiling failed.'

SlipperyPickle

2015-03-08 11:59:55

From: nero_dante
I tried that lol, still gives this error

'Error: Found unexpected token "else", expected "End" at line 37
Compiling failed.'


procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText(['alk Log Bea']) then //<--- Add the '[]', because it needs an array.
fastClick(MOUSE_LEFT) //Here was the ';', remove this <------------
else begin
wait(500);
writeLn('Can not find Looking again');
terminateScript();
end;
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end;

If you change the above, it should work.

the bank

2015-03-08 12:06:48

The better option is to enclose any condition statements that will resolve to an else inside a begin/end.

IE:

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText(['alk Log Bea']) then
begin
fastClick(MOUSE_LEFT);
end else
begin
wait(500);
writeLn('Can not find Looking again');
terminateScript();
end;
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end;

nero_dante

2015-03-08 12:15:53

Yeah I added in the '[]' and it runs the script, but it doesn't seem to find the mouse over text that I wrote. This is the error I'm getting now.

'– isMouseOverText()
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
—- Current mouse-over text: "Walk Log beam"
– isMouseOverText(): False
Can not find Looking again
– Succesfully freed SMART[22200]
Successfully executed.'

SlipperyPickle

2015-03-08 12:21:00

You have Bea in capital. But it's beam (in lowercase).

nero_dante

2015-03-08 12:23:41

From: SlipperyPickle
You have Bea in capital. But it's beam (in lowercase).


Damn lol, didn't know something like that would be affected. Thanks. sorry about that xD

Hoodz

2015-03-08 13:43:09

From: the bank
The better option is to enclose any condition statements that will resolve to an else inside a begin/end.

IE:

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText(['alk Log Bea']) then
begin
fastClick(MOUSE_LEFT);
end else
begin
wait(500);
writeLn('Can not find Looking again');
terminateScript();
end;
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end;


that looks ugly

the bank

2015-03-08 14:41:26

From: hoodz
that looks ugly


I disagree. Disregarding a semi-colon just so that it can *technically* execute is the ugly option in my mind. Pascal is the only native language where something like that would ever be acceptable, and its not "meant" to work, it just does because of lax restrictions.

Hoodz

2015-03-08 15:32:56

From: the bank
I disagree. Disregarding a semi-colon just so that it can *technically* execute is the ugly option in my mind. Pascal is the only native language where something like that would ever be acceptable, and its not "meant" to work, it just does because of lax restrictions.


its just unnecessary extra code imo

Solar

2015-03-08 17:56:46

I think it looks better without the begin and end, but I like to use the begin and end just to make it a bit more consistent with any other if statements.
I see it as being one less thing that you need to remember too.