Medal of
Honor: Pacific Assault Scripting Standard
����� The
is also difficult to debug due to the lack of debugging
tools.� Te goal of this document is to
make scripts easier to read, more readily understandable, and therefore easier
to debug by you and whoever is going to end up trying to understand���� your script.� Please use this document and map 5_6_village
as a guide when creating your scripts.
1) Header at the top of every script file containing the
following information:
//-----------------------------------------------------------------------------
//
//� scriptname.scr
//
//� <description
here>
//
//-----------------------------------------------------------------------------
===============================
===============================
2) Function blocks should start like this:
//-----------------------------------------------------------------------------
FunctionNameHere:
//
// description of the functions purpose
//
//-----------------------------------------------------------------------------
����� waitthread
DoStuff
����� end
===============================
===============================
3) A function that has parameters passed into it should
start like this:
//-----------------------------------------------------------------------------
FunctionNameHere local.parm1 local.parm2 local.parm3:
//
// description of the functions purpose
//
// parm1 - comment defining parm1 and what it is
// parm2 - comment defining parm2 and what it is
// parm3 - comment defining parm3 and what it is
//
//-----------------------------------------------------------------------------
����� waitthread
DoStuff local.parm1 local.parm2 local.parm3
����� end
===============================
===============================
3) Bracing style should be with the braces lined up with
its corresponding if/while command
//-----------------------------------------------------------------------------
FunctionNameHere:
//
// description of the functions purpose
//
//-----------------------------------------------------------------------------
����� if( condition
)
����� {
����������� while (
condition2 )
����������� {
����������������� waitthread
DoStuff
����������������� waitthread
DoMoreStuff
����������������� waitthread
DoEvenMoreStuff
����������� }
����� }
����� end
===============================
===============================
4) NO ASSIGNMENTS are to be done inside of if(), while(),
or for() statments.� This is to help
prevent the common typo of '=' vs. '=='.�
So for example:
Legal:
if( checkForCondition == TRUE )
{
����� waitthread
DoStuffHere
}
NOT LEGAL:
if( (someVariable = X + 10) == TRUE )
{
����� waitthread
DoStuffHere();
}
===============================
===============================
5) When naming functions, capitalize each logical word in
the name.�
Example:
(less desirable)
my_function_name:
myfunctionname:
myFunctionName:
(more desirable)
MyFunctionName:
===============================
===============================
6) When naming variables, the first letter of the
variable should be lowercase.� Each
subsequent logical word in the name should be capitalized.
Example:
(less desirable)
level.SuperCoolVariable
level.supercoolvariable
level.super_cool_variable
(more desirable)
level.superCoolVariable
===============================
===============================
7) Comment your code.��
Good commenting is the key to team collaboration when multiple people
are going to be handing off scripts to one another.�
===============================
===============================
8) When naming variables and functions, pick descriptive
names that make sense and are understandable in terms of reading the code and
finding out what that function / variable does.�
One should almost be able to understand and read the script just from
the variable and function names along.�
It is much better to write a sentence for a name, than to have a simple
'e1' for a variable name.�
===============================
===============================
9) Old C style block comments using - /* */ - should only
be done when temporarily commenting out blocks of actual code.� This method should NOT be used for the
permanent comments
CORRECT METHOD:
/*
����� //--- spawn an
explosioin
����� $plasma4_spawn.modelname
( "fx/fx-sml-exp.tik" );
����� $plasma4_spawn.spawntargetname
( "plasma4_boom" );
����� trigger (
"$plasma4_spawn" );
����� $plasma4_spawn.remove
();
*/
WRONG METHOD:
/*
this function is used to move the elevator between m1l1 and
m1l2
*/
===============================
===============================
10) Only leave commented out code in the code if it needs
to be visible for some reason.
===============================
===============================
11) Do not swear/cuss/use "bad words" in your
scripts.� Players have access to and will
read whatever we write in the script. �
===============================
===============================
12)� The main
script should have minimal code in it.�
Its main responsibility is to setup all the sub-scripts (scripts in the
map's sub-folder), initialize global variables, and start the level.�
===============================
===============================
13)� Whenever
possible, use the thread or waithread command instead of a for loop.� It makes the code easier to read (and write
for that matter).
// example:
// less desireable
����� for
(local.i=1;local.i<=$squad.size;local.i++)
����� {
����������� $squad[local.i].var1
= 5
����������� $squad[local.i].var2
= 7
����� }
// more desireable:
����� $squad
waitthread InitSquad
����� end
//
------------------------------------------------------------
InitSquad:
//
------------------------------------------------------------
����� self.var1 = 5
����� self.var2 = 7
����� end
===============================
===============================
14) Use the "waitthread" command over the "thread"
command whenever possible.� The thread
command creates a new thread that is put on the queue to be executed later. The
waitthread command executes the thread and returns immediately.
����� - Valid uses
for thread over waitthread is where the thread you're creating is intended on
sticking around for a while or implements code that will do a "wait"
of some sort.
// Example:
// bad thread command
����� $squad thread
InitSquad
����� $squad
waitthread DoSomethingElse.
����� // this is bad
because the code inside of InitSquad actually executes AFTER the code in
DoSomethingElse.
// Valid use of the thread command:
����� $squad thread
TrackDeath
����� end
//
------------------------------------------------------------
TrackDeath:
// ------------------------------------------------------------
����� level.count ++
����� self waittill
death
����� level.count --
����� end
�����
===============================
===============================
15) Keep tabs instead of spaces.� Tabs should be set to 4.� In whatever text editor program you use, you should be able to set this under preferences.� If you are using notepad or wordpad, come see me and we'll get you setup with a proper text / code editing program.