SRL Archive - OSR Help

Help With Loops


GREEN GIANT

2013-07-16 13:50:01

Hello everyone,
I have been making good progress using simple functions and procedures to pathwalk, open doors teleport etc but now that i'm trying to implement failsafes and loops i'm failing terribly.

The script below should find the function 'CastleDoorColor' and then check for the uptext 'oor' and then check for the option 'wait' before clicking on x,y. Although the script compiles and runs it does not check for uptext or option and simply clicks the door ignoring my if and then loops. Can anyone point out my faults?

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
MMouse(x, y, 0, 0);
if isuptext('oor') and
WaitOption('pen', 500) then
writeln('woot');
ClickMouse(x, y, 1);
end;

rj

2013-07-16 14:11:42

You need to have begin and ends if you want it to do something that's more then one line(hard to explain)

for example:

If (atBank) then
OpenBank;
Closebank;

the above would only "OpenBank" and then it would do "closeBank" no matter if at the bank or not, so you would have to be it in begin and end blocks like this:

if (atBank) then
begin
OpenBank;
CloseBank;
end;

If the condition is met it would do everything inside of the begin and end.

Also, if this is for RS don't use ClickMouse, that will get you banned use ClickMouse2,

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
MMouse(x, y, 0, 0);
if (isuptext('oor') and WaitOption('pen', 500)) then
begin
writeln('woot');
ClickMouse2(Mouse_Left);
end;
end;

Try that out

GREEN GIANT

2013-07-16 14:30:51

Thanks 'Officer Barbray', i tried your changes but it doesn't seem to work. It compiles and finds the door but does not click it, i realised that waitoption is not suitable for a check and so changed it to optionexists but still doesnt click the door :(

Its also worth noting that its doesnt write 'Woot' so im guessing the problem is within the uptext and option part? The option i have on the door is 'Open Large Door'

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
MMouse(x, y, 0, 0);
if (isuptext('oor') and optionsexist(['pen', 'open'], true)) then
begin
writeln('woot');
ClickMouse2(Mouse_Left);
end;
end;
end;

loragnor

2013-07-16 14:31:27

From: GREEN GIANT
Hello everyone,
I have been making good progress using simple functions and procedures to pathwalk, open doors teleport etc but now that i'm trying to implement failsafes and loops i'm failing terribly.

The script below should find the function 'CastleDoorColor' and then check for the uptext 'oor' and then check for the option 'wait' before clicking on x,y. Although the script compiles and runs it does not check for uptext or option and simply clicks the door ignoring my if and then loops. Can anyone point out my faults?


One issue is the structure of the procedure. See my code below for the differences:

Procedure FindDoorClick;
var
x, y: integer;
begin
// This is one conditional block that will move the mouse to x,y if the
// color is found
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
MMouse(x, y, 0, 0);
// This is another conditional block that will write 'woot' in the
// debug box if both conditions are met
if isuptext('oor') and WaitOption('pen', 500) then
writeln('woot');
// This is not contained in a conditional block, so it will happen
// whether the second conditional block is satisfied or not
ClickMouse(x, y, 1);
end;

I have not tested this, but you should need to right click the door to get the options menu. As it is, you are moving the mouse over the door, and isuptext('oor') may return true. But, you will also need to have waitoption('pen',500) return true.

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
AL_HumanMMouse(Point(x, y), 0, 0); // More humanlike mouse movement
ClickMouse2(mouse_right); // Opens the options menu
if isuptext('oor') and WaitOption('pen', 500) then
begin // This allows you to bundle both these statements within the second conditional block
writeln('woot');
ClickMouse2(mouse_left); // Opens the door
end
end
else
srl_warn('FindDoorClick','Could not find the color',warn_Debug);
end;

rj

2013-07-16 14:36:02

Ahh I see the issue, your giving it no time to check for the uptext, try this:

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
MMouse(x, y, 0, 0);
if WaitUpText('oor',600) and WaitOption('pen', 500)) then
writeln('woot');
end;
It will check for the uptext until 600 ms are up, and if it finds and will choose the door option

EDIT: I took out the ClickMouse2 because waitOption will choose it for you

GREEN GIANT

2013-07-16 14:54:24

From: loragnor
One issue is the structure of the procedure. See my code below for the differences:

Procedure FindDoorClick;
var
x, y: integer;
begin
// This is one conditional block that will move the mouse to x,y if the
// color is found
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
MMouse(x, y, 0, 0);
// This is another conditional block that will write 'woot' in the
// debug box if both conditions are met
if isuptext('oor') and WaitOption('pen', 500) then
writeln('woot');
// This is not contained in a conditional block, so it will happen
// whether the second conditional block is satisfied or not
ClickMouse(x, y, 1);
end;

I have not tested this, but you should need to right click the door to get the options menu. As it is, you are moving the mouse over the door, and isuptext('oor') may return true. But, you will also need to have waitoption('pen',500) return true.

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
AL_HumanMMouse(Point(x, y), 0, 0); // More humanlike mouse movement
ClickMouse2(mouse_right); // Opens the options menu
if isuptext('oor') and WaitOption('pen', 500) then
begin // This allows you to bundle both these statements within the second conditional block
writeln('woot');
ClickMouse2(mouse_left); // Opens the door
end
end
else
srl_warn('FindDoorClick','Could not find the color',warn_Debug);
end;


Thanks Loragnor, i tried your alterations and first of all i got an error for AL_humanMMouse, is this because im using SRL-OSR? I changed out the AL_Human for MMouse just to test it, it now right clicks but does not click it, i tried removing the waitoption just to make sure it wasnt that but to no avail :(

GREEN GIANT

2013-07-16 15:07:35

Haha i finally figured it out. Seems it was my silly mistake all along, both Loragnor and Officers alterations worked it was my flawed logic that was failing :(

Turns out that the 'uptext' and 'optionsexist' cannot both be simultaneously true as when the door is right clicked the top corner uptext disapears :p

Just out of interest then, can anyone tell what function would search for the 'Open' part of an uptext, as im pretty sure uptext searches only search for the cyan colored text.

Thanks.

Just out of interest

rj

2013-07-16 15:08:30

From: GREEN GIANT
Haha i finally figured it out. Seems it was my silly mistake all along, both Loragnor and Officers alterations worked it was my flawed logic that was failing :(

Turns out that the 'uptext' and 'optionsexist' cannot both be simultaneously true as when the door is right clicked the top corner uptext disapears :p

Just out of interest then, can anyone tell what function would search for the 'Open' part of an uptext, as im pretty sure uptext searches only search for the cyan colored text.

Thanks.

Just out of interest



It reads all of the uptext not just the cyan

loragnor

2013-07-16 15:14:43

From: GREEN GIANT
Thanks Loragnor, i tried your alterations and first of all i got an error for AL_humanMMouse, is this because im using SRL-OSR? I changed out the AL_Human for MMouse just to test it, it now right clicks but does not click it, i tried removing the waitoption just to make sure it wasnt that but to no avail :(


1 - I think you're right that AL_HumanMMouse does not work in OSR. Sorry for that.
2 - In looking into the functions, I see that waitoption will left click the chosen option, so the second clickmouse is not needed.

As per Officer Barbrady's suggestion, I would use the waituptext func. Play around with the wait times. It could be that you are not giving the functions enough time to find the necessary text. One of the things about waitoption is that it will perform the check on options text up to 5 times, once for each color of the types of options text. Start off with WaitOption('oor', 2000) or higher, working your way down until it doesn't work. [shrug]

You could also try the 'multi' versions of these functions:

if WaitMultiUpText(['pen large door','pen','arge','oor'],2000) and WaitOption('pen',2000) then

GREEN GIANT

2013-07-16 15:34:56

Thanks guys, I've finally got it where i want it to be, your help is greatly appreciated :)

It now searches for 'CastleDoorColor', if found and the uptext 'Open' is available it will click the door and write "Opening door!" before opening it. If however the color is found but the uptext 'Close' is found it will write "Door already open!" and continue with the rest of the script…i hope.

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
MMouse(x, y, 0, 0);
wait(1000);
if isuptextmulticustom(['pen','Open','open']) then
begin
writeln('Opening Door!');
ClickMouse2(Mouse_Left);
end else

if isuptextmulticustom(['lose','Close','close']) then
writeln('Door is already open!');
end;
end;

loragnor

2013-07-16 15:48:29

From: GREEN GIANT
Thanks guys, I've finally got it where i want it to be, your help is greatly appreciated :)

It now searches for 'CastleDoorColor', if found and the uptext 'Open' is available it will click the door and write "Opening door!" before opening it. If however the color is found but the uptext 'Close' is found it will write "Door already open!" and continue with the rest of the script…i hope.

Procedure FindDoorClick;
var
x, y: integer;
begin
if (FindColorSpiral(x, y, CastleDoorColor, 193, 9, 342, 337)) then
begin
MMouse(x, y, 0, 0);
wait(1000);
if isuptextmulticustom(['pen','Open','open']) then
begin
writeln('Opening Door!');
ClickMouse2(Mouse_Left);
end else

if isuptextmulticustom(['lose','Close','close']) then
writeln('Door is already open!');
end;
end;


Cool. Glad I could be of some help. More glad you've got it doing what you want. :)