SRL Archive - News and General

Scripting templates? Do you use one?


Wizkid

2011-07-22 08:28:20

Do you guys use templates when you create your own scripts?

If so, care to share?
Let's see who got the biggest template :D
Post them!


My in-progress template. I'll only make single user scripts as I only have one account :duh:

program VerySimpleCowKiller;
{$DEFINE SMART}
{$i srl\srl.scar}
{$i reflection\reflection.simba}

var
Form: TVariantArray;
MyForm : TForm;
Edits: Array [0..1] of TEdit;
List: TComboBox;
Terminate: Boolean;

procedure OnStart(Sender : TObject);
var
Run: Boolean;
begin;
Run := True;

HowManyPlayers:= 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := Edits[0].Text;
Players[0].Name := Edits[1].Text;
Players[0].Active := True;

If Lowercase(List.Text) = 'lampskill' then
begin
Run := False;
Writeln('Choose a lampskill!');
end;

If (Edits[0].Text = '')or(Edits[1].Text = '')or(Edits[0].Text = 'Username')or(Edits[1].Text = 'Password') then
begin
Run := False;
Writeln('Please fill in the form correctly!');
end;

If Run then
MyForm.ModalResult:= mrOk;
end;

procedure OnExit(Sender : TObject);
begin;
MyForm.ModalResult:= mrOk;
Terminate := True;
end;

function FormInit: Boolean;
var
Button: Array [0..1] of TButton;
I: Integer;
SArr: TStringArray;
begin;
Result := false;
MyForm := TForm.Create(nil);
MyForm.Width := 100;
MyForm.Height := 200;
MyForm.BorderStyle := bsNone;

For I:=0 to 1 do
begin
Edits[I] := TEdit.Create(MyForm);
Edits[I].Parent := MyForm;
Edits[I].SetBounds(10, 40+(I*35), 80, 30);
end;
Edits[0].Caption := 'Username';
Edits[1].Caption := 'Password';
Edits[1].PasswordChar := '*';

List := TComboBox.Create(MyForm);
List.Parent := MyForm;
List.SetBounds(10, 10, 80, 25);
List.Caption := 'Lampskill';
SArr := ['Attack', 'Strength', 'Defence', 'Range', 'Magic', 'Hitpoints',
'Prayer', 'runecrafting', 'Agility', 'Herblore', 'Theiving', 'Crafting',
'Fletching', 'Slayer', 'Mining', 'Smithing', 'Fishing', 'Cooking',
'Firemaking', 'Woodcutting', 'Farming', 'Construction', 'Hunter', 'Summoning'];
For I:=0 to High(SArr)do
List.ITEMS.Add(SArr[I]);

For I:=0 to 1 do
begin
Button[I] := TButton.Create(MyForm);
Button[I].Parent := MyForm;
button[I].SetBounds(5+(I*50), 150, 40, 25);
end;

Button[0].OnClick := @OnStart;
Button[0].Caption := 'Start';
Button[1].OnClick := @OnExit;
Button[1].Caption := 'Exit';

MyForm.ShowModal;
MyForm.Free;
end;

Procedure ShowForm;
begin
ThreadSafeCall('FormInit', Form);
end;

begin
SMART_Members := False;
SMART_Server := 32;
SMART_Signed := True;

{Setup}
SetupSRL;
ShowForm;

If Terminate then
TerminateScript;

Writeln('Player: ' + Players[0].Name);
end.

Home

2011-07-22 08:38:28

I ususally use.
Extensions –> SRL –> Open.

~Home :)

Markus

2011-07-22 09:08:59

I just take the previous script I made, rip everything out that doesn't have to do anything with what I'm doing now then that is my 'template' :)

KingKong

2011-07-22 09:13:23

Here is mine(a bit of it anyway):

program new;
{.include SRL\SRL\misc\smart.scar}
{.include col.simba} //my own file :P
{.include ref.simba} //this one too :D

const
Scriptname = 'Template';

procedure Log(Command, Scriptname: String; Keynames, Values: TStringArray);
//Doesn't really work atm, just started on this yesterday.
{Commands are as follows:
'Start' - Records the date and time the script was started.
'End' - Records the date and time the script was ended.
'Save' - Saves the progress reports for the current scripts.
}
var
a, Runs: Integer;
begin
Runs := StrToInt(ReadINI('Log Information', 'Total runs ', AppPath + 'Scripts\Logs\' + Scriptname + '.ini'));
Inc(Runs);
case Lowercase(Command) of
'start' : WriteINI('Run ' + ToStr(Runs) , 'Started ', ' ' + TheDate(1) + ' at ' + TheTime, AppPath + 'Scripts\Logs\' + Scriptname + '.ini');
'save' :
for a:= 0 to High(Keynames) do
WriteINI('Run ' + ToStr(Runs), Keynames[a], Values[a], AppPath + 'Scripts\Logs\' + Scriptname + '.ini');

'end' :
begin
WriteINI('Run ' + ToStr(Runs), 'Finished ', ' ' + TheDate(1) + ' at ' + TheTime, AppPath + 'Scripts\Logs\' + Scriptname + '.ini');
WriteINI('Log Information', 'Total runs ' , ToStr(Runs), AppPath + 'Scripts\Logs\' + Scriptname + '.ini');
end;
end;
end;

procedure SetupScript;
begin
Smart_Members := false;
Smart_Server := 123;
Smart_Signed := true;
Smart_SuperDetail := false;
SetupSRL;
SetupRandomTool(5000, 5, 'alarm.wav');
M_DeclarePlayers;
end;

procedure Finish;
var
sound: Integer;
begin
repeat
OpenWebPage(AppPath + 'finished.vbs');
wait(2000);
Inc(sound);
until(sound = 3);
end;

procedure MainLoop;
var
Keynames, Values: TStringArray;
begin
Log('start', Scriptname, Keynames, Values);
//code here
Keynames:= ['', ''];
Values:= ['', ''];
Log('save', Scriptname, Keynames, Values);
Log('end', Scriptname, Keynames, Values);
end;

begin
SetupScript;
R_UpdateHooks;
try
MainLoop;
except
PlaySound('alarm.wav');
finally
Finish;
end;
end.

mat_de_b

2011-07-22 09:16:13

Copy pretty much everything above my first procedure Declare players function variables i use a lot all the include things.

Then if i have any handy functions i copy those over aswell

footballjds

2011-07-22 09:48:20

From: Markus
I just take the previous script I made, rip everything out that doesn't have to do anything with what I'm doing now then that is my 'template' :)


Same, i re-use 70% of my functions/procedure across my scripts.
speaking of scripts. it's been a long ass time since i've released one… :/

Flight

2011-07-22 10:22:43

I make script outlines in note pad starting with the main stages of a script, for example:

-Mine rocks

-Walk to bank

-Bank

-Walk to rocks


Using those I go into further detail:

-Mine rocks
–Find 'target rock' through obj array
–Track 'target rock'
–Loop until full

-Walk to bank
–Check if we've logged out, if so webwalk the rest of the path

-Bank
–Deposit what we don't need
–Rest if needed

And just keep adding to that.

-Walk to rocks

footballjds

2011-07-22 10:41:25

From: Flight
I make script outlines in note pad starting with the main stages of a script, for examp…
*nerfed*


isn't this considered Pseudocode?

http://en.wikipedia.org/wiki/Pseudocode

Gu3st...

2011-07-22 11:42:38

From: footballjds
isn't this considered Pseudocode?

http://en.wikipedia.org/wiki/Pseudocode
Nah, that's just a list of things he want the script to do, Pseudocode should look like code

footballjds

2011-07-22 11:45:50

From: Zyt3x
Nah, that's just a list of things he want the script to do, Pseudocode should look like code


I suppose you're right.
Depending on the writer, pseudocode may therefore vary widely in style, from a near-exact imitation of a real programming language at one extreme, to a description approaching formatted prose* at the other.
although i guess there's no RIGHT way to write Pseudocode.

I generally write Pseudocode prior to starting on the actual script. I find it helps with logic.
Although my Pseudocode is a bit sloppy :p

*Noun: Written or spoken language in its ordinary form, without metrical structure

TomTuff

2011-07-24 01:55:31


program NewScript;
{$DEFINE SMART}
{$i SRL\SRL.scar}
{$i Reflection\Reflection.Simba}


const
S_World = 33;
S_Signed = True;
S_Member = True;


procedure DeclarePlayer;
begin
with Players[0] do
begin
Name := '';
Pass := '';
Active := True;
end;
end;


begin
Smart_Server := S_World;
Smart_Signed := S_Signed;
Smart_Members := S_Member;
Smart_SuperDetail := False;
SetupSRL;
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
DeclarePlayer;
R_UpdateHooks;
if not(LoggedIn) then
begin
LogInPlayer;
Wait(3000 + Random(2000));
SetAngle(True);
MakeCompass('n');
end else
PlayerStartTime := GetSystemTime;
end.

;)

footballjds

2011-07-24 02:01:35

program new;
begin
end.
what can i say?
It's what i use…