SRL Archive - OSR Help

Beginner question - How do i end script


Risen91

2012-05-01 13:05:52

Hey all, just started out yesterday and I'm starting to learn about the scripting by making a simple bot for flash games. The game I'm working on is Demonic Defense 4 here is the script i have so far:
program SaveTheGoldfish;

procedure StartGame;
begin
MoveMouse(275, 230);
ClickMouse(275, 230, 1);
Wait(10500);
MoveMouse(116, 168);
ClickMouse(116, 168, 1);
Wait(300);
MoveMouse(113, 264);
ClickMouse(113, 264, 1);
Wait(300);
MoveMouse(128, 170);
ClickMouse(128, 170, 1);
Wait(500);
MoveMouse(278, 134);
HoldMouse(278, 134, 1);
MoveMouse(209, 133);
ReleaseMouse(209, 133, 1);
Wait(500);
PressKey(52);
Wait(500);
MoveMouse(314, 160);
ClickMouse(314, 160, 1);
Wait(100);
MoveMouse(314, 160);
ClickMouse(314, 160, 1);
Wait(100);
MoveMouse(314, 160);
ClickMouse(314, 160, 1);
Wait(100);
MoveMouse(314, 160);
ClickMouse(314, 160, 1);
Wait(100);
MoveMouse(314, 160);
ClickMouse(314, 160, 1);
Wait(100);
MoveMouse(314, 216);
ClickMouse(314, 216, 1);
Wait(100);
MoveMouse(314, 216);
ClickMouse(314, 216, 1);
Wait(100);
MoveMouse(314, 216);
ClickMouse(314, 216, 1);
Wait(100);
MoveMouse(248, 269);
ClickMouse(248, 269, 1);
end;

procedure DefendTower;
var
x, y:Integer;
begin
if FindColorSpiralTolerance(x, y, 0 , 142, 187, 547, 397, 5) or
FindColorSpiralTolerance(x, y, 9539985 , 142, 187, 547, 397, 5) or
FindColorSpiralTolerance(x, y, 6684672 , 142, 187, 547, 397, 5) or
FindColorSpiralTolerance(x, y, 6710784 , 142, 187, 547, 397, 5) or
FindColorSpiralTolerance(x, y, 5598082 , 142, 187, 547, 397, 5) then
begin
MoveMouse(x, y);
HoldMouse(x, y, 1);
MoveMouse(60, 77);
ReleaseMouse(60, 77, 1);
end;
end;

procedure KillScript;
begin
while(isKeyDown(27)) do
TerminateScript;
end;

procedure LevelEnd;
var
x1, y1:Integer;
begin
if FindColorSpiralTolerance(x1, y1, 4016735, 253, 211, 326, 234, 5) then
TerminateScript;
end;

begin
StartGame;
Wait(3000);
repeat
LevelEnd;
KillScript;
DefendTower;
until(false);
end.

Ok so, what i want to know is how to make the repeat end once LevelEnd; has completed. At the moment it just kills the script outright (using TerminateScript;) once it detects the level has ended. How would i create maybe a Boolean that tells the "Until" part to be false so the script stops.
So far i have tried adding a variable into the KillScript; (under x1, y1:Integer;) so that once the color is detected it changes to true, but i keep getting errors and i still have no idea how to make the Until detect that and stop repeating.

Hope you understand what I'm asking :P thanks for help in advanced!

x[Warrior]x3500

2012-05-01 13:08:45

turn LevelEnd into a function that return a boolean value. then repeat, until(levelEnd);

Risen91

2012-05-01 13:11:03

Ah would you be amazing and quickly show me what you mean? not sure how to make it return a Boolean value :(

Sowwi if i sound stupid xD started learning this scripting last night, the only other language i know is batch script and thats easy as hell.

bg5

2012-05-01 13:17:16

Look on tutorial island:

http://villavu.com/forum/showthread.php?t=58935

Risen91

2012-05-01 13:35:35

Thanks for the great link ill look over it in detail over the next few days :). could someone still show me how i can correct my code to do what x[Warrior]x3500 said though would love to get this working. thanks!

x[Warrior]x3500

2012-05-01 14:12:30

if you look over the procedures and functions section of the guide provided above, you should be able to figure out how to :)

Risen91

2012-05-01 15:39:51

I have and i still don't get how to return a Boolean. i have changed it too:
     function LevelEnd: Integer;
var
x1, y1:Integer;
begin
if FindColorSpiralTolerance(x1, y1, 4016735, 253, 211, 326, 234, 5) then
Result := 1;
end;
and
  begin
StartGame;
Wait(3000);
repeat
LevelEnd;
KillScript;
DefendTower;
until(levelEnd);
end.
but that's returning a Integer not a Boolean. No idea still how to get it to return true if the function completes.

begginer

2012-05-01 15:42:30

You should try to see the Yohos tut again and try tutorial island

x[Warrior]x3500

2012-05-01 15:46:04

function LevelEnd: Integer; -> function LevelEnd: boolean;

Risen91

2012-05-01 15:46:47

thanks ill try that

Risen91

2012-05-01 15:58:04

works perfect and i can see what i was doing wrong now thanks loads for the help :)!
quick question if anyone's still here,
PressKey(52);
this outputs the number 4 but in the Simba handbook it says that "R: 52". Also the "DELETE: 46" didn't work correctly either.

nickrules

2012-05-01 16:16:04

From: Risen91
works perfect and i can see what i was doing wrong now thanks loads for the help :)!
quick question if anyone's still here,
PressKey(52);
this outputs the number 4 but in the Simba handbook it says that "R: 52". Also the "DELETE: 46" didn't work correctly either.


Use sendkeys/typesend?

m34tcode

2012-05-01 22:29:18

instead of using the number, use the constant associated with your key to be pressed. to seee a list of every possible key that simba can press, type vk_ then press control-space

this will popup the code completion list, which will show all of the possible matching vk values. for 'R', try VK_R. for delete, VK_DELETE