SRL Archive - RS3 Beginner Scripting Tutorials

The Scan and React Method


Obscurity

2015-06-21 00:46:01

The Scan and React Method




Introduction


So, I've seen a lot of scripts from different people. These scripts use various different methods. One prominent method I've seen is the standard loop. Let me give you an example:
program woodChopper;

procedure cutTrees;
begin
writeLN('[procedure] cutTrees');
end;

procedure walkToBank;
begin
writeLN('[procedure] walkToBank');
end;

procedure bankLogs;
begin
writeLN('[procedure] bankLogs');
end;

procedure returnToTrees;
begin
writeLN('[procedure] returnToTrees');
end;

begin
repeat
cutTrees;
walkToBank;
bankLogs;
returnToTrees;
until false;
end.
This can work for some situations. However, if anything unexpected happens, it can often break the script. Say, for whatever reason, it fails to bank the logs. It's got to run through 3 other procedures before hopefully fixing the issue.

Scan and React


This is exactly like it sounds. You scan, and then you react accordingly. I can try to explain it, but since most people learn by example:
program fighter;

var
vDropModelID:array of uInt32=[123456,456789,789123];
vMonsterModelID:uInt32=987654321;
vProcedure:procedure();

procedure pAttackMonster;
var
canAttack:countDown;
monsterModels:glModelArray;
begin
repeat
monsterModels:=ogl.getModels(vMonsterModelID).getVisible();
if canAttack.isFinished() and length(monsterModels) then
begin
mouse.rightClickOption(monsterModels.closestTo(ogl.getClientMidPoint())[0],'Attack');
canAttack.setTime(1000);
end;
until combat.hasTarget() or monsterModels.isEmpty();
end;

procedure pLookForMonster;
var
canLook:countDown;
monsterModels:glModelArray;
begin
repeat
monsterModels:=ogl.getModels(vMonsterModelID).getVisible();
if canLook.isFinished() and monsterModels.isEmpty() then
begin
mainScreen.setDegrees(random(360),random(20,50));
canLook.setTime(3000);
end;
until not monsterModels.isEmpty();
end;

procedure pTakeDrop;
var
canTake:countDown;
dropModels:glModelArray;
begin
repeat
dropModels:=ogl.getModels(vDropModelID).getVisible();
if canTake.isFinished() and length(dropModels.isEmpty()) then
begin
mouse.rightClickOption(dropModels.closestTo(ogl.getClientMidPoint())[0],'Take')
canTake.setTime(1000);
end;
until dropModels.isEmpty();
end;

begin
repeat
if length(ogl.getModels(vDropModelID)) then //~ Scan
vProcedure:=@pTakeDrop //~ React
else if length(ogl.getModels(vMonsterModelID)) and (not combat.hasTarget()) then //~ React
vProcedure:=@pAttackMonster //~ React
else if ogl.getModels(vMonsterModelID).isEmpty() then //~ React
vProcedure:=@pLookForMonster //~ React

ogl.callProcedure(@vProcedure);
until false;
end.

That's about it. As I haven't dealt with color, apart from just recently using getColor(), but it's great for OpenGL.

Hope this helps some people!

Citrus

2015-06-21 01:28:21

Nice tutorial! I appreciate that it's short and to the point.

I guess I use the 'standard' loop, but I 'scan' on the first line of each procedure so that it exits if the 'scan' doesn't check out.
e.g. my abyss rc mainloop

procedure mainLoop();
begin
bank();
runToMage();
clickThings();
chargePouches();
enterAltar();
craftRunes();
end;
can be started at any point along the way, so it's just a matter of where you want to put those scans.
I'll definitely give this method a shot and see how I like it.