SRL Archive - First Scripts

Emp


AliveDrive

2014-02-14 18:02:21

So I am working on my first script, and it's not easy.

But I've decided if I can solve one problem at a time, I may eventually get a working copy out there.

The issue I am currently experiencing is that the script doesn't seem to know when it has a full inventory or not.

The code I am using.

//=========================================\\
// \\
// INV FULL CHECK \\
// \\
//=========================================\\
function InvFull() : Boolean;
begin
if not isLoggedIn() then
exit;

if (tabBackpack.isFull()) then
begin
writeln('Inv Full!');
result := true;
end;
end;

Example of how I am calling it.

if (GPS = 'Bank') and InvFull() then

Any suggestions?

Currently it will always try to deposit inventory.

The Mayor

2014-02-14 18:12:16

From: AliveDrive
So I am working on my first script, and it's not easy.

But I've decided if I can solve one problem at a time, I may eventually get a working copy out there.

The issue I am currently experiencing is that the script doesn't seem to know when it has a full inventory or not.

The code I am using.

//=========================================\\
// \\
// INV FULL CHECK \\
// \\
//=========================================\\
function InvFull() : Boolean;
begin
if not isLoggedIn() then
exit;

if (tabBackpack.isFull()) then
begin
writeln('Inv Full!');
result := true;
end;
end;


Example of how I am calling it.

if (GPS = 'Bank') and InvFull() then

Any suggestions?

Currently it will always try to deposit inventory.



There is no need for this whole function - tabBackpack.isFull() achieves exactly the same result :p


if (GPS = 'Bank') and tabBackpack.isFull() then
begin
writeLn('We are at the bank with a full inventory');
//do stuff
end;

Foundry

2014-02-14 18:14:31

It looks fine to me. It's either the way it checks if the inventory is full or the (GPS = 'Bank') part.

AliveDrive

2014-02-14 18:19:46

Thanks for the quick reply guys.

Mayor, you're right but I figured out why it wasn't working.

Your tutorial informed me that you always need a begin..end after an if..then if you have more than one command.

The GPS code is something from another post I commented on, I need to make the script always know where it is.

//=========================================\\
// \\
// GPS \\
// by Sjoe \\
//=========================================\\
function GPS(): String;
var
p: Tpoint;
begin
if (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) then
Result := 'Bank';

if (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
Result := 'Shop';

if not (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) or not (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
begin
Result := 'Cave';
inEssCheck;
end;
end;

Sk1nyNerd

2014-02-14 19:12:21

From: AliveDrive
Thanks for the quick reply guys.

Mayor, you're right but I figured out why it wasn't working.

Your tutorial informed me that you always need a begin..end after an if..then if you have more than one command.

The GPS code is something from another post I commented on, I need to make the script always know where it is.

//=========================================\\
// \\
// GPS \\
// by Sjoe \\
//=========================================\\
function GPS(): String;
var
p: Tpoint;
begin
if (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) then
Result := 'Bank';

if (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
Result := 'Shop';

if not (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) or not (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
begin
Result := 'Cave';
inEssCheck;
end;
end;


after you have your result you can exit the function

Result := 'Bank';
Exit;

you can check where you are by using this in other procedures if(Result = 'Bank') then

AliveDrive

2014-02-14 19:45:05

So the code I am trying to use now looks like this.

//=========================================\\
// \\
// GPS \\
// by Sjoe \\
//=========================================\\
function GPS(): String;
var
p: Tpoint;
begin
if (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) and distance(minimap.getCenterPoint(), p) < 5 then
Result := 'Bank';
exit;

if (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) and distance(minimap.getCenterPoint(), p) < 5 then
Result := 'Shop';
exit;

if not (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) and not (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
Result := 'Cave';
exit;
end;

Is checking the distance from the symbol unnecessary?

This is how I am trying to use it. Is this incorrect?

procedure mainLoop;
begin
repeat
if not isLoggedIn then
playerSetup;
//A SPACE GOES HERE!!!!!!!!!!!!
GPS; //EDIT! Remember kids, scripting is a black-hearted siren.

if (GPS = 'Bank') and (tabBackpack.isFull()) then
begin
findBanker;
depositEss;
end;

if (GPS = 'Bank') and (not tabBackpack.isFull()) then
begin
walkToAubury;
end;

Foundry

2014-02-14 20:33:30

From: Sk1nyNerd
after you have your result you can exit the function

Result := 'Bank';
Exit;

you can check where you are by using this in other procedures if(Result = 'Bank') then


With Lape you can also do exit(whatever your result is here).

exit('Bank');

slacky

2014-02-15 07:21:36

From: AliveDrive
So the code I am trying to use now looks like this.

//=========================================\\
// \\
// GPS \\
// by Sjoe \\
//=========================================\\
function GPS(): String;
var
p: Tpoint;
begin
if (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) and distance(minimap.getCenterPoint(), p) < 5 then
Result := 'Bank';
exit;

if (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) and distance(minimap.getCenterPoint(), p) < 5 then
Result := 'Shop';
exit;

if not (minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds)) and not (minimap.findSymbol(p, MM_SYMBOL_SHOP_MAGIC, minimap.getBounds)) then
Result := 'Cave';
exit;
end;
…


You forgot begin end, since you have more then one statement after the "if"'s.

...
if (Minimap.FindSymbol(p, MM_SYMBOL_BANK, Minimap.GetBounds)) and (Distance(Minimap.GetCenterPoint(), p) < 5) then
begin
Result := 'Bank';
Exit();
end;
...

Better option is mentioned above, and will look something like this:

...
if (Minimap.FindSymbol(p, MM_SYMBOL_BANK, Minimap.GetBounds)) and (Distance(Minimap.GetCenterPoint(), p) < 5) then
Exit('Bank');
...