SRL Archive - Scripting Tutorials

Request a Function/Procedure


Dynamite

2011-12-31 13:03:59

So I will start up a little service where people can post a Function/Procedure that they want to know about and I will tell them about it and how to use it.

:) <3
-Boom

[Nathan]

2011-12-31 13:07:20

Your answers should be compiled and added to the docs for functions that don't have an example with them (90% of them)

Swatarianess

2012-01-01 10:12:32

One i dont understand are these :/


GetTextat()
GetTextatEx()
GetTextatExWrap()
GetTextATPA()

No idea of any of these 0.0 i saw how they were used for;
GetBlackChatMessage();

Confuses my brain so can you like explain it so i can get text from Screen :/

Brandon

2012-01-02 20:18:46

From: bro433
One i dont understand are these :/

Confuses my brain so can you like explain it so i can get text from Screen :/


GetTextAt(const atX, atY, minvspacing, maxvspacing, hspacing,color, tol, len: integer;const font: string): string;

Reads text starting from X, Y.. min v spacing is the vertical spacing, hspacing is horizontal spacing. len = length of the text.. font = the font name such as:
'Courier New'..

As for GetTextAtEx.. it does the same thing except it finds text in a given box from X1, Y1, X2, Y2.. that way you don't need to specify the length of the text.. rest of parameters are the same as the above..

Now for GetTextWrapper.. don't use it.. just ignore it.. its a wrapper for the functions above..

GetBlackChatText is the system text that runescape displays in your chatbox.. such as stuff that happens in the game..

Example: 'the box slowly opens…', 'You haven't received any messages to which you can reply.'.. 'your dueling ring has 7 charges left'..
etc..

For GetTextATPA.. same as the above functions except it reads text from a T2DPointArray. That's all of them I think.
See here for other text functions I guess:
http://docs.wizzup.org/simba/scriptref/ocr.html

Swatarianess

2012-01-03 06:22:40

From: ggzz
GetTextAt(const atX, atY, minvspacing, maxvspacing, hspacing,color, tol, len: integer;const font: string): string;

Reads text starting from X, Y.. min v spacing is the vertical spacing, hspacing is horizontal spacing. len = length of the text.. font = the font name such as:
'Courier New'..

As for GetTextAtEx.. it does the same thing except it finds text in a given box from X1, Y1, X2, Y2.. that way you don't need to specify the length of the text.. rest of parameters are the same as the above..

Now for GetTextWrapper.. don't use it.. just ignore it.. its a wrapper for the functions above..

GetBlackChatText is the system text that runescape displays in your chatbox.. such as stuff that happens in the game..

Example: 'the box slowly opens…', 'You haven't received any messages to which you can reply.'.. 'your dueling ring has 7 charges left'..
etc..

For GetTextATPA.. same as the above functions except it reads text from a T2DPointArray. That's all of them I think.
See here for other text functions I guess:
http://docs.wizzup.org/simba/scriptref/ocr.html


Ahhhh ok the Spacings are what made me get wierd texts like;

" Bse$2 de$f"s*oe"

instead of;

"Grand Exchange"

Makes sense thanks i'll try it again and see the outcome :). I havent seen many people explain the spacings but i get it its the spacings for the Vert spacings and Horizontal spacings ^^

Dynamite

2012-01-03 12:07:03

I am so sorry, I don't even remember posting this thread xD
Thanks ggzz <3

Man16

2012-01-04 18:06:09

Please, I beg of you, help me. I'm looking for some documentation of an api or something which contains all the functions/procedures which are built into Simba. Some of these functions would be like the bank ones where DepositAll; would do what it suggests. Where could I find functions like these? Thanks

Brandon

2012-01-04 18:13:00

From: Man16
Please, I beg of you, help me. I'm looking for some documentation of an api or something which contains all the functions/procedures which are built into Simba. Some of these functions would be like the bank ones where DepositAll; would do what it suggests. Where could I find functions like these? Thanks



See where the blue circle/oval/whatever is? Click there and start typing the name of a function and it will narrow everything down.. from there you can double click the narrowed down results and it will show you the documentation for the function.. if it doesn't, it's built into the simba.exe itself or a plugin and would require that you go here and look for it:
http://wizzup.org/simbafpcdoc/index-8.html

OR

https://github.com/MerlijnWajer/Simba


Another tip is that if you see someone using a function in a script you like, hold control button on the keyboard and click the function, it'll jump to the include or wherever the function's documentation is..

Dynamite

2012-01-04 18:23:04

To add on to ggzz's post, simply try going to: C://Simba/Includes/SRL (As long as defaults are set)
You will find all of the include files in there with the functions and procedures inside them.
That is where you will learn the most.

-Boom

John

2012-01-16 07:07:07

nvm

Bobzilla69

2012-01-16 07:14:22

From: Evlin
could some one make me a that goes from edgy bank to the strong hold down inside the rock through the portal down the other ladder then walks through some doors to the flesh crawlers? I have tried myself with sps, radial walking and dtm walking i keep getting numerous errors if some one could do this for me and pm it to me, it would be extremely appreciated.
I am working on the fighting area of my script and the banking area(banking is 80% done). If you have the time/knowledge then give it a go ;)

here are some pics of the location
Location: Edgeville to Stronghold of Security.

Stronghold of Security:



Prayer: Not required.

~Evlin


This is not a request thread its about asking what functions/procedures do.

bg5

2012-01-17 21:28:24

Hello
I don't get QuickTPASort
procedure QuickTPASort(var A: TIntegerArray; var B: TPointArray; iLo, iHi: Integer; SortUp: Boolean);

What are iLo ,iHi parameters? What criteria it use for sort?

Also I'm not sure if i understand InvertTPA. It just swap x and y in all TPoints?

And third question: is there any function ,which removes duplicated points from TPA?

edit:

Last one - Whats the difference between SortATPAFromFirstPoint and SortATPAFrom ?

redgiant61

2012-01-19 06:14:43

Hi. first of all, Thank you for taking your time to help other people.

I made this procedure

Procedure ChopRoot;
var x, y: integer;
begin
if FindObj(x, y, 'hop', 2380663, 35) then
begin
FindNormalRandoms;
Mouse(x, y, 2, 2, true);
ChooseOption('hop');
if not FindObj(x, y, 'hop', 2446713, 35) then
begin
FindNormalRandoms;
Mouse(x, y, 2, 2, true);
ChooseOption('hop');
end;
end;
end;

According to what i think ive done, it shld chop one root, and if it doesnt find it, chop the other root…But it doesnt do that. it chops one root and then stops. Ik ive gone wrong somewhere, but Where?

Sorry if im not supposed to post this question here.

Thanks in advance! =]

Striken

2012-01-28 23:01:10

Okay so I have created this procedure :

procedure WalkBank;
begin
FindNormalRandoms;
SPS_Setup(RUNESCAPE_SURFACE,['12_8','12_7']);
WriteLn('Inventory is full. Proceeding to bank.');
WalkToBank := [Point(4965, 3205), Point(4983, 3184), Point(5003, 3154), Point(5008, 3119), Point(5005, 3076), Point(5004, 3033), Point(4987, 2991), Point(4979, 2956), Point(4954, 2937), Point(4909, 2935), Point(4873, 2941), Point(4855, 2934), Point(4853, 2974)];
SPS_WalkPath(WalkToBank);
WriteLn('We have arrived at the bank.');
end;

Whenever I compile the whole script itself this happens
[Error] (38:1): Identifier expected at line 37
Compiling failed.

Still learning how to make a script. Just trying to compile the script before my first script is done =)

NickMystre

2012-01-28 23:08:42

You need to declare 'WalkToBank' as a TPointArray - either globally, or preferrably locally - ie in the procedure you use it.

var
WalkToBank:TpointArray;

Striken

2012-01-28 23:10:01

From: NickMystre
You need to declare 'WalkToBank' as a TPointArray - either globally, or preferrably locally - ie in the procedure you use it.

var
WalkToBank:TpointArray;


I put it at the top :

{$DEFINE SMART}
{$i srl/srl.simba}
{$i sps/sps.simba}
Var
WalkToBank:TPointArray;
WalkToMine:TPointArray;

That is the position. DEFINE SMART is right under "Program"

NickMystre

2012-01-28 23:12:38

Which line of code is no 37 ?

Striken

2012-01-28 23:17:08

I fixed it up but when I compile now a new tab in simba comes up with the title 'Sps' I know what it means but gives me this error in the Debug Box.

[Error] C:\Simba\Includes\Sps/Sps.simba(136:34): Unknown identifier 'MMCX' at line 135
Compiling failed.

NickMystre

2012-01-28 23:30:48

MMCX, which is defined in globals.simba, is the x-coordinate for the Minimap centre.

globals.simba is loaded when you include srl.simba (I think)

Can you post all the code you have so far ?

Striken

2012-01-28 23:31:19

The code for my script itself?

If so I can send it to you over MSN.

[email]Phyaskou@hotmail.com[/email]

NickMystre

2012-01-28 23:34:11

Send it to me via PM (private message)

You do this by left clicking my name (in my post), and choosing send private message

Striken

2012-01-28 23:47:14

Sent it. I hope you know how to fix this :)

NickMystre

2012-01-28 23:48:47

Yes, I've PM'd you the code.

You will also need to declare or remove SIGNED. It's only referenced once. OK ?

Striken

2012-01-28 23:53:50

I took that out. THANK YOU SO MUCH!!
It has finally compiled.
Now for the final result….testing it out :)

NickMystre

2012-01-28 23:58:44

Instead of taking it out, I see that you miss-spelt SIGNED …

const
{==========Smart Setup==========}
World = 0; // Input the runescape world number right here for it to select. You may leave it as 0 if you would like it to select a random world.
MEMBERS = False; // Select False if you are not a member. Select True if you are a member.
SINGED = True;

… change it to SIGNED. As you need this and the other variables as well.

Good luck! :)

Striken

2012-01-29 00:02:14

Oh. I guess I didn't notice that :O

Thanks for the advice and help. You've helped me finish my first script :)

NickMystre

2012-01-29 00:03:13

No trouble at all. Good luck!

Striken

2012-01-30 01:53:39

"[Error] (55:1): Identifier expected at line 54
Compiling failed."

This happened when I tried to compile my script after adding a proggy system. If anyone can help me I can send the entire script so you can help me out.

NickMystre

2012-01-30 01:56:05

Just post the procedure / function that line 54 is in.

Striken

2012-01-30 01:58:47

procedure WalkBank;

Daniel

2012-01-30 02:07:07

From: Phyaskou
procedure WalkBank;


Did you miss an end; ?

Striken

2012-01-30 02:08:59

From: Daniel
Did you miss an end; ?


Turns out that I did. I had to put another 'End;' before the 'procedure WalkBank;'

Thanks :)

Daniel

2012-01-30 02:26:18

From: Phyaskou
Turns out that I did. I had to put another 'End;' before the 'procedure WalkBank;'

Thanks :)


All goods :) Do you need any more help? :)

Striken

2012-01-30 02:33:14

From: Daniel
All goods :) Do you need any more help? :)


Trying to add Progress Report System but it doesn't seem to work……

Striken

2012-01-31 20:54:59

Getting this when I try to compile my SwampToad Picker :
"[Error] (59:12): Unknown identifier 'x' at line 58
Compiling failed."

if FindObj(x, y, 'taircase', 396561, 3) then

That is the line it says that at.

Daniel

2012-02-01 00:13:05

From: Phyaskou
Getting this when I try to compile my SwampToad Picker :
"[Error] (59:12): Unknown identifier 'x' at line 58
Compiling failed."

if FindObj(x, y, 'taircase', 396561, 3) then

That is the line it says that at.


You need to declare 'x', like so: var x: Integer; :)

Striken

2012-02-01 00:20:18

That worked and I forgot the ';' everytime after every procedure so it didn't compile until I figured it out.

Striken

2012-02-05 20:08:08

Edit : Nvm. Fixed it up.

Joe

2012-02-17 20:42:46

what does tpointarray do? I was making a universal walkbank; procedure and i cant seem to get it to stick? any tips, dymamite?

poopy2177

2012-02-19 15:59:27

Alright I gotta question ok so basically I want it to click the circled water source symbol
and I never want it to click the other one to the north so I would like some help on FindSymbolMulti and stuff like that

also one more question
how do I do like
if not findobj for 5000 then
basicaly I want it if it cant find a warrior for five seconds then have it click on the circled water source to find more of em

Striken

2012-03-10 16:50:20

procedure Obstacle;
var x, y: integer;
begin
repeat
FindNormalRandoms;
WriteLn('Looking for obstacle net.');
if FindObj(x, y, 'bstacle net', 4084847, 10) then
WriteLn('Climbing Obstacle.');
Mouse(x, y, 0, 0, true);
If isUpText('limb-over') then
ChooseOption('limb-over');
end;

[Error] (34:1): Identifier expected at line 33
Compiling failed.

Line 33 is "end;"

Google

2012-04-03 19:32:58

function TrapDoorColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.20, 0.35);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 6186359, MSX1, MSY1, MSX2, MSY2, 24);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 2.76) and (X <= 36.79) and (Y >= 2.82) and (Y <= 37.91) and (Z >= 2.39) and (Z <= 40.51) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

ACA function for finding the door colors but I couldn't seen to find anywhere how to add in to climb down it, anyone free to help would be greatly appreciated.
-GOOGLE

putonajonny

2012-04-06 10:42:41

From: poopy2177
Alright I gotta question ok so basically I want it to click the circled water source symbol
and I never want it to click the other one to the north so I would like some help on FindSymbolMulti and stuff like that

also one more question
how do I do like
if not findobj for 5000 then
basicaly I want it if it cant find a warrior for five seconds then have it click on the circled water source to find more of em


There is a function
 FindSymbol(var rx, ry: Integer; Name: string) : Boolean;

you could do something like

Procedure ClickFountain;
Var
x, y : integer
begin
if(FindSymbol(x, y, 'water source'))then
Mouse(x, y, 5, 5, mouse_Left);
end;

From: Phyaskou
procedure Obstacle;
var x, y: integer;
begin
repeat
FindNormalRandoms;
WriteLn('Looking for obstacle net.');
if FindObj(x, y, 'bstacle net', 4084847, 10) then
WriteLn('Climbing Obstacle.');
Mouse(x, y, 0, 0, true);
If isUpText('limb-over') then
ChooseOption('limb-over');
end;

[Error] (34:1): Identifier expected at line 33
Compiling failed.

Line 33 is "end;"


You need an "Until" at the end for your "Repeat" part:
Repeat
ItIsRaining;
Until(ItIsntRaining);

So yours would look like:
procedure Obstacle;
var
x, y: integer;
begin
repeat
FindNormalRandoms;
WriteLn('Looking for obstacle net.');
if FindObj(x, y, 'bstacle net', 4084847, 10) then
begin
WriteLn('Climbing Obstacle.');
Mouse(x, y, 0, 0, true);
If isUpText('limb-over') then
begin
ChooseOption('limb-over');
exit;
end;
Until(false);
end;

From: GOOGLE
function TrapDoorColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.20, 0.35);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 6186359, MSX1, MSY1, MSX2, MSY2, 24);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 2.76) and (X <= 36.79) and (Y >= 2.82) and (Y <= 37.91) and (Z >= 2.39) and (Z <= 40.51) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

ACA function for finding the door colors but I couldn't seen to find anywhere how to add in to climb down it, anyone free to help would be greatly appreciated.
-GOOGLE


I think you have used the wrong thing in ACA, use ACA again but us the FindObject, post what you get and I will help you turn that into a function for going down the trap door..

samuri51

2012-05-26 19:58:19

i have two questions

1. how do i use the MouseBox function(how do I find the coordinates of the box I want to make and how to do i make the box)

2. not sure how to ask this so ill post some code from yojo's script, basically how do i use a function like this to accurately pick colors in my script…. I tried using object tpa's and it fails…. when i try to find colors in the mining guild it keeps finding the black outline of the map(color 0) even when its not highlighted in ACA. even when I adjust the color tolerence to 0 it still finds the outside of the map >.>

Function MineRock(WutRock:Integer):Boolean;
var I,PlusOne,tMine,J, L:Integer;
RockInFoI: TIntegerArray;
RockInFoE: TExtendedArray;
RockPts:TPointArray;
RockPtsBox: T2DPointArray;
BingoPt: TPoint;

Begin

If Not(LoggedIn) Then Exit;

J:=0;

//StatsGuise('Searching For Rock: '+ IntToStr(InvCount));
If InvFull Then Exit;

Case WutRock of
1: Begin RockInFoE:=[0.02 , 3.07]; RockInFoI:=[4622062, 5]; End; //BCop
2: Begin RockInFoE:=[0.03 , 0.09]; RockInFoI:=[4088717, 9]; End; //DCop
3: Begin RockInFoE:=[0.13 , 0.33]; RockInFoI:=[11382456, 12]; End; //Tin
4: Begin RockInFoE:=[0.06 , 0.87]; RockInFoI:=[3293285, 7]; End; //Iron
5: Begin RockInFoE:=[0.00 , 0.53]; RockInFoI:=[1579546, 5]; End; //Iron
End;


{Get Rock Points Only}
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(RockInFoE[0],RockInFoE[1]);
FindColorsSpiralTolerance(MSCX, MSCY, RockPts, RockInFoI[0], MSX1, MSY1, 507, 270, RockInFoI[1]);
SetColorSpeed2Modifiers(0.2,0.2);
ColorToleranceSpeed(1);

RockPtsBox:=TPAtoATPAEx(RockPts,35,35);
//DebugATPA(RockPtsBox, '');
{/Get Rock Points Only}

L:= High(RockPtsBox)

For I:=0 To L Do

Begin

PaintReport;
If GetArrayLength(RockPtsBox)>7 Then
Begin

BingoPt:= MiddleTPA(RockPtsBox);
If CheckAndClick('ine', BingoPt.x,BingoPt.y, 'L') Then
Begin
PlusOne:=InvCount+1;
Result:=True;
MarkTime(tMine);
StatsGuise('Mining Rock: '+ IntToStr(InvCount+1));
Players[CurrentPlayer].Loc:='Mining';
wait(500 + Random(1000));
MMouse(582, 228, 7, 7);
Repeat
PaintReport;

Antiban;

RT:=GetSystemTime;
If FindNormalRandoms Then
IncEx(WeMined,GetSystemTime - RT);

// If Random(2500)=1 Then SleepAndMoveMouse(3500+Random(500));

Until (InvCount = PlusOne) Or (TimeFromMark(tMine) > ((Players[CurrentPlayer].Integers[2]*1000) + Random(500)));
If InvCount=PlusOne Then
Begin
DebugXP;

Inc(J);
Inc(TOres);
Inc(Players[CurrentPlayer].Integers[80]); //Ores

Case Players[CurrentPlayer].Integers[1] Of

1,2: Stats_IncVariable('Copper Ore (Mined)', J);
3: Stats_IncVariable('Tin Ore (Mined)', J);
4: Stats_IncVariable('Iron Ore (Mined)', J);
5: Stats_IncVariable('Coal Ore (Mined)', J);

End;

Stats_IncVariable('Total EXP Gained', Round(J*(Players[CurrentPlayer].Extendeds[1])));
IncEx(TExperiance, Round(J*(Players[CurrentPlayer].Extendeds[1])) );

J:= 0;

If ( (TOres Mod 28) = 0 ) Then
Begin
If TOres=0 Then Exit;
Inc(TLoads);
stats_IncVariable('Loads Done', 1);
Inc(Players[CurrentPlayer].Integers[81]); //Total Loads
Inc(Players[CurrentPlayer].Integers[82]); //Temp Loads
ProgressReport;
End;

PaintReport;
Break;
End;
Exit;
End Else Continue;
End Else Continue;
End;
End;

Abu

2012-05-27 10:47:20

From: samuri51
i have two questions

1. how do i use the MouseBox function(how do I find the coordinates of the box I want to make and how to do i make the box)

2. when i try to find colors in the mining guild it keeps finding the black outline of the map(color 0) even when its not highlighted in ACA. even when I adjust the color tolerence to 0 it still finds the outside of the map >.>



For your first problem:

Imagine the box you want to search in.

Now get the color picker tool and click the top left hand corner of the box.
Now click the bottom right hand corner of the box.

Now get those 4 numbers(2 coordinates) and replace them with xs, ys, xe and ye within the MouseBox function. It will now click within the box you want it to.


For your second problem:

Make sure you search within the mainscreen. to do this replace xs, ys, xe and ye in your color finding function with MSX1, MSY1, MSX2, MSY2

Master BAW

2012-06-15 07:31:54

Is there a code to restart the script after a certain amount of time? Like a sleep function? If something goes wrong, I want my script to stop and restart from the top after 30 minutes.
Is there a function to do this or another way?

putonajonny

2012-06-15 07:50:18

From: MasterCrimez
Is there a code to restart the script after a certain amount of time? Like a sleep function? If something goes wrong, I want my script to stop and restart from the top after 30 minutes.
Is there a function to do this or another way?


Depending on how you have structured your script this could be very easy or involve a lot of re-structuring.. you'll have to post what you have…

Master BAW

2012-06-15 12:00:41

I think I have just figured it out.


program stopifyouwantabreak;

function mainloop: boolean;
vars
stoptime : integer;

begin
//the purpose of the function.......here
if(something = wrong) then
begin

//you want it to stop,
stoptime = 3600;//in seconds
result:= false;
exit;

end;

//the rest of your mainloop function.... but whenever you want to stop, you just fill in stoptime, result false and exit;

end;

begin
repeat
repeat
mainloop;
logout;
wait(stoptime*1000);

until stop=true;


until false;
end.



Will this work? Or is the variable stoptime I make in the function mainloop only functional in the function? I don't know if that's true in pascal, but in PHP this wouldn't work…. ;)

and this way is maybe a little too hard, because if i also want to let it happen in other functions, (for example I use a function for checking a random, I want to logout and retry after 30 minutes if it fails) if this happens and it isnt in the main function, exit doesnt work because then it will only go back to the mainloop function…. is there a piece of code that will exit all your functions? Like
exit(ALL);


Thanks for your help, and if this isnt' the best way, please give me a little example for a better way.:)

Runaway

2012-06-15 12:34:31

From: MasterCrimez
I think I have just figured it out.

[snip…]

Will this work? Or is the variable stoptime I make in the function mainloop only functional in the function? I don't know if that's true in pascal, but in PHP this wouldn't work…. ;)

and this way is maybe a little too hard, because if i also want to let it happen in other functions, (for example I use a function for checking a random, I want to logout and retry after 30 minutes if it fails) if this happens and it isnt in the main function, exit doesnt work because then it will only go back to the mainloop function…. is there a piece of code that will exit all your functions? Like
exit(ALL);


Thanks for your help, and if this isnt' the best way, please give me a little example for a better way.:)


What you're looking to do could be as simple as:


var
BreakTime, t: Integer;

begin
BreakTime := (30 * 1000);
repeat
SetupScript;
// ...
MarkTime(t);
repeat
MainLoop;
// ...
if BreakEarly then // Nifty feature #1
Break;
if NoBreak then // Nifty feature #2
MarkTime(t);
until (TimeFromMark(t) >= BreakTime)
until (Whatever)
end.

Master BAW

2012-06-15 15:58:34

From: Runaway
What you're looking to do could be as simple as:


var
BreakTime, t: Integer;

begin
BreakTime := (30 * 1000);
repeat
SetupScript;
// ...
MarkTime(t);
repeat
MainLoop;
// ...
if BreakEarly then // Nifty feature #1
Break;
if NoBreak then // Nifty feature #2
MarkTime(t);
until (TimeFromMark(t) >= BreakTime)
until (Whatever)
end.


I don't understand. What does Breakearly mean and nobreak?

Runaway

2012-06-15 18:29:15

From: MasterCrimez
I don't understand. What does Breakearly mean and nobreak?


Well it was just a suggestion so that you don't end up breaking out of the "mainloop" every 30 minutes. That seems somewhat predictable; to me at least. I guess I could show you how I meant for those variables to be used:


var
BreakTime, t: Integer;
BreakEarly, NoBreak: Boolean;
// ^ Note that these are global vars

procedure HandleBreak;
var
Rand: Integer;
begin
if BreakEarly or NoBreak then
Exit;
Rand := Random(500);
case Rand of
0: BreakEarly := True;
1: NoBreak := True;
end;
end;

begin
BreakTime := (30 * 1000);
BreakEarly := False;
NoBreak := False;
repeat
SetupScript;
// ...
MarkTime(t);
repeat
HandleBreak;
MainLoop;
// ...
if BreakEarly then // Nifty feature #1
begin
BreakEarly := False;
Break;
end;
if NoBreak then // Nifty feature #2
begin
NoBreak := False;
MarkTime(t);
end;
until (TimeFromMark(t) >= BreakTime)
until (Whatever)
end.

Taking a look back at your original code, I think you might be confused because your MainLoop has repeats. This would only work if you don't repeat your MainLoop inside the MainLoop. Instead you use the repeats of what I did above to cycle through the HandleBreak, MainLoop, etc. So you essentially make your MainLoop equivalent to one load, or one complete cycle of your script. Then it will check for a BreakEarly and a NoBreak quite often.

Master BAW

2012-06-15 19:00:40

thanks!