SRL Archive - Outdated Tutorials

Scripting Standards


WhiteShadow

2007-01-01 02:25:15

Scripting Standards by White Shadow.

So why use standards, doesn't the code still frkkin` compile?!
Yes it does, but you may cause many people to go blind and also confuse yourself. People would learn from your code much faster too.

Now let's learn some standards:

CamelBackStyle - UpperCase the words in variables, procedures, program Names, functions, ect.

NO:
[PHP]var
omgiamaleeth4x0r;[/PHP]
Yes:
[PHP]var
OmgIAmALeetH4x0r;[/PHP]
*Don't forget to space twice. Did you notice you even read the 2nd one faster?

Always space after the begins and statements[if..then, while..do, for..to..do, ect.] - So people can tell what loop this part of the code is in.

NO:
[PHP]procedure tutstandards;
begin
writeln('yo yo yo');
end;[/PHP]
Yes:
[PHP]procedure TutStandards;
begin
Writeln('yo yo yo');
end; [/PHP]

NO:
[PHP]program New;

procedure iamcool;
var i:string;
begin
i:='no your not';
if(i='no your not')then
begin
writeln('uh oh you are doushbag');
end;
end;

begin
iamcool;
end.[/PHP]
YES:
[PHP]program New;

procedure IAmCool;
var
i : string;
begin
i:= 'no your not';
if(i = 'no your not')then
begin
Writeln('uh oh you are doushbag');
end;
end;

begin
IAmCool;
end.[/PHP]

1 Space at arithmetic signs too.

Be consistent with if thens - Put your damn if then statement.

NEVER:
[PHP]program New;
{.include SRL/SRL.Scar}
begin
setupsrl;
findsymbol(x,y,'bank');
mouse(x,y,0,0,true,flag);
end.[/PHP]
Notice if the FindSymbol result were false you would click right at 0, 0. Detectable, and stupid yes?
YES:
[PHP]program New;
{.include SRL/SRL.Scar}

begin
SetUpSRL;
if(FindSymbol(x, y, 'bank'))then
begin
Mouse(x, y, 0, 0, true);
Flag;
end;
end.[/PHP]

Beautiful, only clicks and flags when symbol is actually there. Notice, also space at each parameter, very clean and organized.

repeat..until - the code inside repeat until loops should always be 2 spaces from the repeat and the until aligned with the repeat.

NO:
[PHP]program New;
{.include SRL/SRL.Scar}

begin
repeat
writeln('what the hell is this?');
writeln('don''t be gay don''t type like this!');
until(false)
end.[/PHP]
Yes:
[PHP]begin
repeat
Writeln('Mmmhmm good job');
Writeln('I love you too, deary');
until(false)
end.[/PHP]

Parentheses - "(" Use them!

NO:
[PHP]procedure number;
var num,num2:integer;
begin
num:=3;
num2:= 3;
if num=3 or num2=3then
writeln('yes');
end;

begin
number;
end.[/PHP]
This will actually give you an error. ^
Yes:
[PHP]procedure Number;
var
num, num2 : Integer;
begin
num:= 3;
num2:= 3;
if(num = 3) or (num2 = 3)then
Writeln('yes');
end;

begin
Number;
end.
[/PHP]
Notice the CamelBackStyle, space 1 the variable declarations, space 1 arithmetic signs, use parentheses, 2 spaces after a statement.

I add more later, the thing is space to show people different loops and shiet. Don't cram it or align it all to the left it's annoying!

I add more later! k thx for now.

White Shadow.

Dankness

2007-01-01 02:40:34

Always space after Paranthases(sp) see code


begin
if ( I = 1 ) then
Mouse ( X, Y, 3, 3, True );
end;

WhiteShadow

2007-01-01 02:52:54

From: Dankness
Always space after Paranthases(sp) see code


begin
if ( I = 1 ) then
Mouse ( X, Y, 3, 3, True );
end;


I no like dudey. It is confuzzling. :cool:

ilikegrapesoda72

2007-01-06 19:36:58

This will also help other scripters to easily discern your script and help you/give suggestions.

Mithril Fish

2007-01-14 15:51:23

My suggestion: learn python, most of this stuff is required and it will help you get good habits for programming :)