PDA

View Full Version : help me better understand how to loop, PLEASE!



chief herb
04-23-2017, 08:38 PM
i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight

here is my loop.. so far... lmao i know:duh: :google:

begin
cleardebug;
//setupSRL();
repeat
begin
lowprayer;
Combat;
LootMoney;
wait(1000);
ClickNpc;
writeLn('gainz!');
wait(10000)
end;
until (false)
end.

acow
04-23-2017, 09:52 PM
https://villavu.com/forum/showthread.php?t=58935

http://i.imgur.com/Wq8SRST.png Programming statements section of that thread sounds to me like what you're looking for.

the bank
04-23-2017, 10:43 PM
i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight

here is my loop.. so far... lmao i know:duh: :google:

begin
cleardebug;
//setupSRL();
repeat
begin
lowprayer;
Combat;
LootMoney;
wait(1000);
ClickNpc;
writeLn('gainz!');
wait(10000)
end;
until (false)
end.

begin
cleardebug;
//setupSRL();
repeat
begin
while (lowprayer or Combat) do
wait (100 + Random(100));
LootMoney;
wait(1000);
ClickNpc;
writeLn('gainz!');
wait(10000)
end;
until (false)
end.

Where:
lowPrayer() and combat() return a boolean.

Laquisha
04-23-2017, 11:06 PM
i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight

I'd go something like


begin
cleardebug;
setupSRL();

repeat

if (LowPrayer() or (not Combat())) then
begin
WriteLn('Low prayer & not in combat - Looting');
LootMoney();
end else
begin
WriteLn('Clicking NPC');
ClickNpc();
end;

until (false)

end.

the bank
04-24-2017, 12:49 AM
I'd go something like


begin
cleardebug;
setupSRL();

repeat

if (LowPrayer() or (not Combat())) then
begin
WriteLn('Low prayer & not in combat - Looting');
LootMoney();
end else
begin
WriteLn('Clicking NPC');
ClickNpc();
end;

until (false)

end.


This code will repeatedly click the NPC until LowPrayer is true, and in the case that LowPrayer is true it will immediately start looting without waiting for combat to end.

chief herb
02-22-2018, 01:27 AM
begin
cleardebug;
//setupSRL();
repeat
begin
while (lowprayer or Combat) do
wait (100 + Random(100));
LootMoney;
wait(1000);
ClickNpc;
writeLn('gainz!');
wait(10000)
end;
until (false)
end.

Where:
lowPrayer() and combat() return a boolean.

how do i make them return as a boolean?

Citrus
02-22-2018, 10:18 PM
how do i make them return as a boolean?

quick answer: use a function

better answer: you should read everything here: https://villavu.com/forum/showthread.php?t=58935
There is a section called "Procedures and Functions"

chief herb
02-25-2018, 04:20 AM
quick answer: use a function

better answer: you should read everything here: https://villavu.com/forum/showthread.php?t=58935
There is a section called "Procedures and Functions"
program new;
{$DEFINE SMART} // comment this line out if you don't want to use SMART
{$i srl-6/srl.simba}

function waitClientReady(): boolean;override;begin result:= true;end
var
x, y : integer;

const
lowpray :=2070783;
combat :=37890;
col :=37890;

function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;

function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;


procedure lowprayer; //finds low prayer
var
x, y : integer;
begin
if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then
begin
writeLn('low prayer');
//prayer;
wait(2000);
end;
end;

procedure combat;
var
x, y : integer;
begin
if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
begin
writeln('in combat');
wait(500);
end
end

begin
cleardebug;
//setupSRL();
repeat
begin
while (LowPrayer or InCombat) do
wait (100 + Random(100));
lowprayer;
combat;
wait(100);
writeLn('???!');
wait(1000)
end

until (false)
end.

Error: Found unexpected token "739", expected "Identifier" at line 14

Citrus
02-26-2018, 12:25 AM
..

I made some changes to your code and wrote some comments. It should work fine if the colors and coordinates are correct.


program new;
{
var
x, y : integer; //x and y are very common variable names, so it's bad practice to use them as global variables
}
{
const
lowpray :=2070783; //typically '=' is used for constants, not ':='
combat :=37890; //and the constant name is all caps
col :=37890;
}
const
LOWPRAY = 2070783;
COMBAT = 37890;
COL = 37890;

{
function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;
}
//you are trying to insert an already defined constant into this functions parameters, which just doesn't make any sense
//you have a function called 'LowPrayer', and a procedure below called 'lowprayer', which doesn't make sense. also this function has no implementation

{
function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;
}
//(same comments as function LowPrayer..)

{
procedure lowprayer; //all you need to do is change this to a function
var
x, y : integer;
begin
if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then
begin
writeLn('low prayer');
//prayer;
wait(2000);
end;
end;
}

function LowPrayer(): Boolean; //this is a function. 'Boolean' is the return type
var
x, y : integer;
begin
Result := FindColorTolerance(x, y, LOWPRAY, 739, 69, 756, 80, 0);
//'Result' is a sort of implicit variable that will be returned when you call a function
//in this case, it's a boolean that will be true if 'FindColorTolerance' is true
end;

{
procedure combat;
var
x, y : integer;
begin
if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
begin
writeln('in combat');
wait(500);
end
end
}

function InCombat(): Boolean; //same as 'LowPrayer'
var
x, y: Integer;
begin
Result := FindColorTolerance(x, y, col, 13, 33, 16, 48, 5);
end;

begin
ClearDebug();
repeat
while (LowPrayer or InCombat) do
wait (100 + Random(100));
wait(100);
until (false);
end.

chief herb
02-26-2018, 05:51 AM
I made some changes to your code and wrote some comments. It should work fine if the colors and coordinates are correct.


program new;
{
var
x, y : integer; //x and y are very common variable names, so it's bad practice to use them as global variables
}
{
const
lowpray :=2070783; //typically '=' is used for constants, not ':='
combat :=37890; //and the constant name is all caps
col :=37890;
}
const
LOWPRAY = 2070783;
COMBAT = 37890;
COL = 37890;

{
function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;
}
//you are trying to insert an already defined constant into this functions parameters, which just doesn't make any sense
//you have a function called 'LowPrayer', and a procedure below called 'lowprayer', which doesn't make sense. also this function has no implementation

{
function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;
}
//(same comments as function LowPrayer..)

{
procedure lowprayer; //all you need to do is change this to a function
var
x, y : integer;
begin
if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then
begin
writeLn('low prayer');
//prayer;
wait(2000);
end;
end;
}

function LowPrayer(): Boolean; //this is a function. 'Boolean' is the return type
var
x, y : integer;
begin
Result := FindColorTolerance(x, y, LOWPRAY, 739, 69, 756, 80, 0);
//'Result' is a sort of implicit variable that will be returned when you call a function
//in this case, it's a boolean that will be true if 'FindColorTolerance' is true
end;

{
procedure combat;
var
x, y : integer;
begin
if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
begin
writeln('in combat');
wait(500);
end
end
}

function InCombat(): Boolean; //same as 'LowPrayer'
var
x, y: Integer;
begin
Result := FindColorTolerance(x, y, col, 13, 33, 16, 48, 5);
end;

begin
ClearDebug();
repeat
while (LowPrayer or InCombat) do
wait (100 + Random(100));
wait(100);
until (false);
end.


thank you, I'm pretty sure I have a better understanding of boolean's and how to incorporate them into my future scripts! and also some script etiquette/standards! im going to pm you "my"(usedlightly) current fighting script to look over, hope you dont mind... its not the best but it works fairly decent i must say. i just need to incorporate pixelshift or something to be able to tell if a monster is in combat..