Smarter Child
2009-08-07 22:09:34
Hi everybody, today I will be teaching all of you how to use counting in your scripts and use it in your progress reports.
In Scar, there is a function that will increase an integer each time you call it, it is called: Inc/IncEx.
Inc/IncEx in manual:
[php]procedure Inc(var X);
Increases X with 1.
procedure IncEx(var X; N: Integer);
Increases X with N.
[/php]
Note: In Inc, each time it is called, it increases by 1. Whereas in IncEx, it can increase by however you like.
Using Inc in a runescape script:
Now you can see how this is helpful. :).
Using IncEx in a runescape script:
So both are useful!
There is an alternative to Inc/IncEx though.
To what i believe, Inc is a little faster, but has a like a really really rare chance to fail.
Adding this to progress reports:
Proggies say things like: You have done: 35 loads
But how does it know how many loads have been done?
This is where one function comes in:
IntToStr(i: int64): string : This function converts and integer to a string, so that you can display the amount of loads/logs banked in a progress report.
How to use this wonderful function?
Example:
Its pretty simple :p
But to end my tutorial run this script in Scar to see an example of these unbelieveable functions in action! :D"
^ : Look at debug box!
Edit:
- For counting items that you are banked, it would be more efficient if you use ItemAmount in amount.scar.
Its pretty straight foward but i will show an example.
Please Rep+ and click the eggs!
Thanks for reading!
In Scar, there is a function that will increase an integer each time you call it, it is called: Inc/IncEx.
Inc/IncEx in manual:
[php]procedure Inc(var X);
Increases X with 1.
procedure IncEx(var X; N: Integer);
Increases X with N.
[/php]
Note: In Inc, each time it is called, it increases by 1. Whereas in IncEx, it can increase by however you like.
Using Inc in a runescape script:
program BankingExample;
{.include SRL\SRL.Scar}
Var
Loads: integer; //the amount of loads is a number.
begin
if OpenBank('veb', true, true)then//opens varrock east bank
begin
DepositAll;//deposits everything in the inventory
Inc(Loads); //increases loads +1
end.Now you can see how this is helpful. :).
Using IncEx in a runescape script:
program MiningExample;
{.include SRL\SRL.Scar}
Var
OresMined: integer; //the amount of ores mined is a number.
begin
if InvFull then //checks if inventory is full
begin
DropAll; //drops all ores
IncEx(OresMined, 28); //Increases ores mined by 28, since an empty inventory can hold 28 ores
end.So both are useful!
There is an alternative to Inc/IncEx though.
program woodcuttingexample;
{.include SRL\SRL.Scar}
Var
logs, loads: integer; //the amount of loads and logs is a number
Procedure Example;
begin
if InvFull then //checks if inventory is full
begin
Logs := Logs + 28; //adds 28 to the logs variable, similar to incex
WalkToBank; //note you would need another function for this to happen :D
OpenBankFast('veb');//opens varrock east bank fast
if DepositAll then //deposits all
begin
Loads := Loads + 1; //One load has taken place, so it adds 1 to loads
closebank; //closes bank
end;
end;
end;To what i believe, Inc is a little faster, but has a like a really really rare chance to fail.
Adding this to progress reports:
Proggies say things like: You have done: 35 loads
But how does it know how many loads have been done?
This is where one function comes in:
IntToStr(i: int64): string : This function converts and integer to a string, so that you can display the amount of loads/logs banked in a progress report.
How to use this wonderful function?
Example:
program woodcuttingexample;
{.include SRL\SRL.Scar}
Var
logs, loads: integer; //the amount of loads and logs is a number
Procedure Example;
begin
if InvFull then //checks if inventory is full
begin
Logs := Logs + 28; //adds 28 to the logs variable, similar to incex
WalkToBank; //note you would need another function for this to happen :D
OpenBankFast('veb');//opens varrock east bank fast
if DepositAll then //deposits all
begin
Loads := Loads + 1; //One load has taken place, so it adds 1 to loads
closebank; //closes bank
end;
end;
end;
Procedure Proggy;
begin
Writeln('Script has banked: ' + IntToStr(Logs)+' Logs')); //You close the string, the use + to add the conversion function, then use + again to add the string
Writeln('You haved done: ' + IntToStr(Loads) + ' Loads')); //""
end;
begin
end.Its pretty simple :p
But to end my tutorial run this script in Scar to see an example of these unbelieveable functions in action! :D"
program New;
var
Logs, Loads: integer;
Procedure C;
begin
IncEx(Logs, 567);
Loads := Loads + 50;
end;
Procedure Proggy;
begin
C;
Writeln('Script has gained ' + IntToStr(Logs) + ' Logs');
Writeln('Script has done: ' + IntToStr(Loads) + ' Loads');
end;
begin
ClearDebug;
Proggy;
end.^ : Look at debug box!
Edit:
- For counting items that you are banked, it would be more efficient if you use ItemAmount in amount.scar.
{*******************************************************************************
function ItemAmount(Area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;
By: masquerader modified by ZephyrsFury
Description: Counts the number of items found with a color in a certain area. (Counts stacks)
Parameters:
Area - 'inv', 'shop', 'bank', 'trade', 'your trade'.
ItemType - 'dtm', 'bmp', 'color', 'bmpmask'.
Item - name/value of your dtm/bmp/color/bmpmask.
Tol - 'dtm' - [] (dtm's can't have tolerance).
'bmp' - [BMPTol].
'color' - [COLOUR Tol, Min Colour Count].
'bmpmask' - [BMPTol, ContourTol].
*******************************************************************************}
function ItemAmount(area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;
var
Coords: TPointArray;
i, h: Integer;
begin
Result := 0;
Coords := ItemCoordinates(Area, ItemType, Item, Tol);
h := High(Coords);
for i := 0 to h do
Result := Result + GetAmount(Coords[i].x, Coords[i].y);
end;Its pretty straight foward but i will show an example.
Procedure LogAmount;
var
Log: integer;
begin
ItemAmount('inv', 'color', Log, [15, 1]); //in the inventory, using a color, with the integer being Log, and 15 is the tolerance
//MinColorCount is the minimum amount of colors to be found
end;Please Rep+ and click the eggs!
Thanks for reading!