SRL Archive - OSR Help

Problem with repeat


juliea

2013-11-19 20:24:44

I made this simple fighting script for a flash game.It is a side scroller game,all the monsters are to the right.When you are close enough to them an instance is triggered and you automatically fight them.
This script was suppose to click to the right(walker procedure),Stop clicking if instant load(load procedure)and comfirm that the battle is over(end battle procedure).The 'walker' and the 'endbattle' procedure works 100% but the 'load' procedure don't the script keeps clicking to the right during the battle it only stop to confirm 'endbattle'.I think it is my repeat part that is wrong. Here is the script.Sorry for my noobiness.

program ninja;
var
x, y:integer;

procedure walker;
begin
Movemouse(928, 576);
wait(500);
clickmouse(928, 576, 1);
wait(500);
releasemouse(x, y, 1);
wait(1000);
end

procedure load;
begin
if findcolorspiraltolerance(x, y, 5461071, 596, 701, 656, 701, 1) then
releasemouse(x, y, 1);
end

procedure endbattle;
begin
if findcolorspiraltolerance(x, y, 8328, 454, 306, 791, 539, 1) then
Movemouse(x, y);
clickmouse(x, y, 1);
wait(500);
releasemouse(x, y, 1);
end

begin
repeat
walker;
load;
endbattle;
until(false);
end.


btw I watched yohoo video tutorial to make this.

bonsai

2013-11-20 09:20:47

Hi Juliea,

I see a couple of issues with the script. You're right, the repeat loop is not doing things the way you want.

You're looping forever calling the walker/load/endbattle over and over. There is nothing to stop it doing this while waiting for the endofbattle. When it starts one it keeps looping and the walker procedure runs and keeps clicking away.

The load procedure seems more like a test to me, something that indicates if the battle started. Also, that procedure is calling releasemouse but I don't think anything was 'holding' the mouse.

That's another thing I see. You're calling clickmouse() with x,y coordinates that seem to be working for you. There is no need to call releasemouse() if you use clickmouse(). The alternative to clickmouse() is to make one call to holdmouse() then another call to releasemouse(). The x,y values those take are where to click, but you've left them blank on your calls to releasemouse().

I made some edits that I think are more in line with what you're trying to do. For the endless loop, I used while(true) do instead of 'repeat until(false)'. They both do the same thing but I think while(true) reads better / is more understandable.

Within that loops there are two more loops, one to call walker until a fight starts and one to wait for the fight to end.

program ninja;
var
x, y:integer;

procedure walker();
begin
Movemouse(928, 576);
wait(500);
clickmouse(928, 576, 1);
wait(1500);
end;

function isInFight(): boolean;
begin
if findcolorspiraltolerance(x, y, 5461071, 596, 701, 656, 701, 1) then
result := true
else
result := false;
end

function endbattle(): boolean;
begin
if findcolorspiraltolerance(x, y, 8328, 454, 306, 791, 539, 1) then
begin
Movemouse(x, y);
clickmouse(x, y, 1);
wait(500);
result := true;
end
else
result := false;
end;

begin
while (true) do
begin
repeat
walker();
until (isInFight());
repeat
wait(300);
until (endbattle());
end;

juliea

2013-11-20 11:08:31

Thank you so much.That actually makes sense.