PDA

View Full Version : A note on ScriptTerminate;



Naum
02-10-2009, 04:38 PM
ScriptTerminate; <-- How to make a Script Print something before terminating

Intro
Hi, and welcome to a short tutorial on how to make a script do or print something before it is terminated. This may seem impossible but it actually very simple.

Method
SCAR calls a procedure called ScriptTerminate before terminating a script. If you dont have it e.g it is set to nil then it won't be called. But this is very usefull in some cases. You must write the procedure yourself.
This could be done as so:
Program ST;

Procedure ScriptTerminate;
Begin
WriteLn('Script has been terminated');
WriteLn('Thx for using');
End;

Begin
Repeat
Wait(800);
If Random(3) = 0 Then TerimateScript;
Until(False);
end.

This script will write in the debug box: 'Script has been terminated', 'Thx for using'; if the case happens that it terminates.


Cases Of Use
Case One : Your woodcutting script is running and you want it to print one last proggie before it ends or the user terminates it.
Program WCScript;
{.Include SRL/SRL.Scar}

Var x, y, Chopped : Integer;

Procedure ScriptTerminate;
Begin
WriteLn('Chopped '+IntToStr(Chopped)+' Logs!');
End;

Begin
SetupSRL;
Repeat
If FindObj(x, y, 'ree', clGreen, 25) Then
Begin
Mouse(x, y, 1, 1, True);
Wait(800 + Random(800));
Inc(Chopped);
End;
Until(InvFull);
End.

This will write in how many logs you have chopped, if you happen to stop it randomly whilst it is working.

Case Two : You want it to Logout before the script terminates
{.Include SRL/SRL.Scar}

Procedure ScriptTerminate;
Begin
LogOut;
End;

Begin
Repeat
WriteLn('Press CTRL+ALT+S');
Wait(800);
Until(False);
End.


EndNote
Script Terminate is a very useful procedure which I wasn't aware of a few months ago. Hope you can learn something from this very 'short tutorial' :).

JAD
02-10-2009, 04:40 PM
Nice tut. I used to wonder how to do this...


If you dont have it e.g it is set to nil then it won't be called. But this is very usefull in some cases. You must write the procedure yourself.

Is it possible you mean set to NUL, not nil?

Naum
02-10-2009, 04:42 PM
Nil is the actual 'command' if you like that SCAR uses :). Though Null is just the same.

JAD
02-10-2009, 04:44 PM
Nil is the actual 'command' if you like that SCAR uses :). Though Null is just the same.

Hmm... Idk why; nil just sounds funny lol.

Dervish
02-10-2009, 05:07 PM
You can, I presume, use something else than Writeln when useing ScriptTerminate like LogOut or Bank or Drop Ores, stuff like that ?

Naum
02-10-2009, 05:12 PM
Yeah, you can do anything you want with it, I'm sure if it has a time limit or anything like that..

Lance
02-10-2009, 05:19 PM
this is realy good, ima use it so that a proggy is thrown in upon termination so the proggy will always be exact x]

ian.
02-12-2009, 11:43 PM
their is also ScriptPause :p

no like ScriptStart or ScriptResume (those don't work).. is their one that does ScriptResume? :D

Sandstorm
02-12-2009, 11:56 PM
Case of Use Three:

Freeing dtms.

{.Include SRL/SRL.Scar}

var
Lolwut : Integer;

Procedure ScriptTerminate;
Begin
FreeDTM(Lolwut)
End;

Begin
Lolwut := DTMFromString('78DA63E460626090616440060E1A720CFC4 01' +
'A24FA1F0818B9816A2451D540646124906603AA9123A0860B 538D' +
'9F810AA63952F8CD010019D30604');
Repeat
WriteLn('Press CTRL+ALT+S');
Wait(800);
Until(False);
End.


~Sandstorm

senrath
02-13-2009, 01:00 AM
Making sure DTMs have been freed, as well as calling one last progress report are what I use it for. Also, in your example script, you misspelled TerminateScript :P

bullzeye95
02-13-2009, 02:09 AM
Nil is the actual 'command' if you like that SCAR uses :). Though Null is just the same.

They're not the same. Null is an empty variant, and nil is, I think, a null pointer. So, not really anything at all.

Da 0wner
02-13-2009, 02:26 AM
var
DTMsLoaded : boolean;

procedure LoadDTMs;
begin
if not DTMsLoaded then
begin
Lolwut := DTMFromString('78DA63E460626090616440060E1A720CFC4 01' +
'A24FA1F0818B9816A2451D540646124906603AA9123A0860B 538D' +
'9F810AA63952F8CD010019D30604');
DTMsLoaded := true;
end;
end;

procedure ScriptTerminate;
begin
if DTMsLoaded then
FreeDTM(Lolwut);
end;


In my scripts DTMs are declared as an array like DTMs[0], DTMs[1], etc. so that it will be easier to free so in my script terminate procedure I use a for i := 0 to High(DTMs) do FreeDTM(DTMs[i];

Also is it possible to make a script not able to terminate?

I know you can do this


procedure ScriptTerminate;
var
haha : boolean;
begin
while not haha do
end;


And, in theory, that would not allow it to end unless of course, haha is set to true...
But is their a way that is uses less resources? Because that locked up my SCAR :D.

Sandstorm
02-13-2009, 02:40 AM
While Not haha Do
Wait(1)


So it doesn't check haha repeatedly?

~Sandstorm

Da 0wner
02-13-2009, 02:50 AM
Yea I just did that...
That does work but it just locks up my SCAR. And you don't need to do wait(1) :D.