SRL Archive - Outdated Tutorials

Scar Scripting Standards


Ejjman

2007-01-20 19:19:00

Ok, I know other people have done this, but I once didn't know them, and the tutorials didn't help me. So, I went into detail on this subject as I like standardizing scripts now.

This below is the Un-Standardized Script we will be using. It is a simple program to write something in the debug.

program WriteInLine;

var writtenxtimes : integer;

const message1 = 'Hi';
const howmanytimes = 10;

procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;

begin
WriteIt;
writeln('Now we are done, finally!');
end.

Ok, so here's our basic script. All it does is says Hi every second until we say it 10 times, or until we say it howmanytimes we have set to. Let's start at the beginning.

program WriteInLine;

var writtenxtimes : integer;

const message1 = 'Hi';
const howmanytimes = 10;

This is not neccesarily standardizing your script, but it can make it look a lot fancier. What you want to do is put the vars and consts in a second line, making it easier to read. Like this.

program WriteInLine;

var
writtenxtimes : integer;

const
message1 = 'Hi';
howmanytimes = 10;

You do not need a second const or var when having another one, just keep it under the const/var word. :)

Now, lets do the Procedure.

procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;

Let's move down the line. First, the standards are two spaces, not a tab, just two spaces. The beginning line is always on the same row as the procedure, but after that, is when you put the spaces. Then, you put two spaces after the repeat also, because this is as if we are using another begin, but we are going to repeat what is in the repeat..until things multiple times. So, now that you have two-spaced all your stuff inside of the repeat. So, your code should look like this.

procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;

Let's move right on down.

begin
WriteIt;
writeln('Now we are done, finally!');
end.

This last part, you should be able to do. Try it on your own!….Ok, so if you know scripting, then this would be called the 'main loop' of the script. It is not a procedure. But anyway, all you need to do is put two spaces before the stuff in the begin..end commands. And it should be…

begin
WriteIt;
writeln('Now we are done, finally!');
end.

Yay! You have standardized your first script! Good job, and I hope you can use this method to make your scripts more clear, and be able to contribute to the community. Thanks, and goodnight.


program WriteInLine;

var
writtenxtimes : integer;

const
message1 = 'Hi';
howmanytimes = 10;

procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;

begin
WriteIt;
writeln('Now we are done, finally!');
end.

c0de

2007-01-20 19:42:18

Hmm, I disagree in some points…

The code should branch like this


Some procedure
|
|Some code with more local things
| |
| |
| |More code with local things
| | |
| | |Blah...
| | |
| |End of local things
| |
|End of first local things
|
End of procedure


So that rule used on this piece of code:
[php]
procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;
[/php]

Would make it look like this:
[php]
procedure WriteIt;
begin
repeat
writeln(message1 + ' ' + inttostr(writtenxtimes + 1));
wait(1000);
writtenxtimes:= writtenxtimes + 1;
until(writtenxtimes >= howmanytimes)
writeln('Awesome, no?');
end;
[/php]


All in all, good job :)

Ejjman

2007-01-20 19:53:12

Ok, I never new that part, but it always made more sense to me to go

Begin
Repeat
Doing this stuff
Until (this happens)
Then come and do this
end

That can be both ways, thanks though :)

Freddy1990

2007-02-25 11:52:43

I'm a perfectionist…
program WriteInLine;

var
WrittenXTimes: Integer;

const
Message1 = 'Hi';
HowManyTimes = 10;

procedure WriteIt;
begin
repeat
WriteLn(Message1 + ' ' + IntToStr(WrittenXTimes + 1));
Wait(1000);
WrittenXTimes := WrittenXTimes + 1;
until (WrittenXTimes >= HowManyTimes);
WriteLn('Awesome, no?');
end;

begin
WriteIt;
WriteLn('Now we are done, finally!');
end.

kornthebldgd

2007-09-07 18:39:48

Nice Standards, Will help some people who have not scripted much.

optikal

2007-10-01 07:54:45

nice thanks for this i have trouble with standards even though i use vB often i have never really applied standards and now i can :)

MasterKill

2007-10-01 08:17:55

I'll send this link to 'dumpin' lol he needs it :p

btw, very nice tut yes.

@freddy: perfect.

wafyl

2007-11-05 17:00:27

Thanks, this really helped!

big boy6

2007-11-17 17:41:57

awsome job this is great, now i can make my own!:D

rogeruk

2007-11-18 07:23:40

program WriteInLine;

var
writtenxtimes: Integer;

const
message1 = 'Hi';
howmanytimes = 10;

procedure WriteIt;
begin
repeat
Writeln(message1 + ' ' + IntToStr(writtenxtimes + 1));
wait(1000);
writtenxtimes := writtenxtimes + 1;
until (writtenxtimes >= howmanytimes)
Writeln('Awesome, no?');
end;

begin
WriteIt;
Writeln('Now we are done, finally!');
end.

Theres a missing ; at the end of until. (Thats why your formatter isnt formating it correct ;))

I always align vars,consts and types.

program WriteInLine;

var
Writtenxtimes: Integer;

const
Message1 = 'Hi';
HowManyTimes = 10;

procedure WriteIt;
begin
repeat
Writeln(Message1 + ' ' + IntToStr(Writtenxtimes + 1));
Wait(1000);
Writtenxtimes := Writtenxtimes + 1;
until (Writtenxtimes >= HowManyTimes);
Writeln('Awesome, no?');
end;

begin
WriteIt;
Writeln('Now we are done, finally!');
end.