SCRIPTS.DOC

./mudd/docs/SCRIPTS.DOC · 8.1 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

******************************************************************************
* Locke's   __ -based on merc v2.2-____        NIM Server Software           *
* ___ ___  (__)__    __ __   __ ___| G| v4.0   Version 4.0 GOLD EDITION      *
* |  /   \  __|  \__/  |  | |  |     O|        documentation release         *
* |       ||  |        |  \_|  | ()  L|        Hallow's Eve 1999             *
* |    |  ||  |  |__|  |       |     D|                                      *
* |____|__|___|__|  |__|\___/__|______|        http://www.nimud.org/nimud    *
*   n a m e l e s s i n c a r n a t e          dedicated to chris cool       *
******************************************************************************

SCRIPT MODIFICATION AND SPECIFICATION DOCUMENT

For NiMUD Scripts

This script language is a function-based language -- which means,
everything is a function.  It is a basic language which is specific to
muds in general.  This is a replacement for the scripting language that
was available in previous NiMUDs -- MobScripts.

This language is called, in the code and in the mud, by the name
"proc" or "script", that is because the type of interpreter designed
is a Procedural Scripting Interpreter (PSI).  I have dubbed the language
"NIMScript" -- if you choose to copy this code onto other muds, refer
to it as NIMScripts.  You are bound by the stipulations in liscense.doc
if you copy and use this software.

Scripts are an important feature NiMUD which is still being developed,
but here is some information to get everyone started scripting.

-Locke
 theisles@nimud.org


      Contents

1     Syntax
1.1   Functions
1.2   Variables and Evaluating Expressions
1.3   Trigger Types
1.4   Naming Conventions

2     Modifying the Language
2.1   Source Code Structure
2.2   How to Add a New Function
2.3   Limitations

3     Function List
3.1   Function Descriptions

4     Tutorials
4.1   Creating A Script
4.2   Using Multiple Scripts
4.3   Examples


1     Syntax
------------------------------------------------------------------------------
This script language is a function-based language -- which means,
everything is a function.  It is a basic language which is specific to
muds in general.  This is a replacement for the scripting language that

was available in previous NiMUDs -- MobScripts.

To set a variable:

%<varname>% <value>;

To call a function:

function( <param1>, <param...x> );

To call nested functions

function( function2( function(3) ) );

** To contain a string or other set of characters, use the {, }
   these brackets take the place of what are usually double quotes (") or
   parenthesis.

Ex:    function({value of string});



1.1   Functions
------------------------------------------------------------------------------
Functions either return a value, or perform an action.  Every function,
in actuality, returns some value, whether that be a simple 0 or 1 (true,
or false) some return strings, some return numbers and values, and some
return pointers, to objects, mobiles or rooms.

A function takes parameters -- these parameter types are unique to each
function.  Passing the wrong type will incur an error in the script.

Examples of valid function calls:

cmp( 1, 2 );
do({'How are things going?});



1.2  Variables
------------------------------------------------------------------------------
Variables can either be set to a value, or can be inserted to evaluate to
their value, based on the context in which their name is used.

Variables are automatically created by the interpreter when you first
reference it.  There are also some variables that are reserved by the
parser for certain values.

These reserved variables are:  %target%  -- which returns the target of
the caller, with respect to the trigger type.  (see trigger types below)
%astr% and %bstr% and %caller% -- see trigger types below

To set a variable:

%varname% <value>;

Example:  %varname% {'Hello!};

To evaluate a variable:
eval(%varname%) or
do(%varname%);



1.3  Trigger Types
------------------------------------------------------------------------------


1.4  Naming Conventions
------------------------------------------------------------------------------


2     Modifying the Language
------------------------------------------------------------------------------


2.1   Source Code Structure
------------------------------------------------------------------------------


2.2   How to Add a New Function
------------------------------------------------------------------------------

Files you need to modify:

function.c
function.h
script.c

Go into function.c first and find the appropriate location for the function.

All functions are given a caller and a type, followed by their parameters.
This is called from script.c in the heart of the interpreter.

First, write your function.  Use other functions as a basis for writing
yours, there are a bunch of functions (basic ones) already coded, which
can be used to learn the syntax.

All functions return VARIABLE_DATA types that must be created in the function,
then returned.  When creating a new variable, you must set its type as
well as its data.  There are four types: objs, mobs, rooms and strings.

Convert numbers to strings for numerical values, they are evaluated later
by other functions (ex: do(wait(4)); )

Then, after you have penned your new function, go into function.h and
add the declaration.

THEN, MOST IMPORTANTLY, add it to the interpreter for testing.
This is found in script.c, search for another function to find it.
Basically, it is a really long IF-then statement.  Place most commonly
used functions at the top of the list.





3     Function List
------------------------------------------------------------------------------

Question:  What is an <expression>?
Answer:    An expression is either a function that returns a value, or a value
           that may contain none or at least one variable

Reserved functions for internal parsing.

goto      ( <label> );
if        (  <expression>, <if-true>, <iffalse> );
label     ( <name> );
return    ( <expression> );
halt      ( <expression> );
permhalt  (  );
wait      (  <duration> );
autowait  (  <duration> );
call      ( <proc-name>, <target> );
vget      ( <new variable>, <target variable>, <proc-name>, <target> );
vset      ( <new variable>, <source variable>, <proc-name>, <target> );

Further stuff.

vcpy      ( <source variable>, <target variable>, <proc-name> ) );
self      ( <variable> );

"Constant"

null      ( );

Boolean conditionals.

cmp       ( <expression>, <expression> );
not       ( <expression> );
or        ( <expression>, <expression> );
and       ( <expression>, <expression> );
xor       ( <expression>, <expression> );
less      ( <expression>, <expression> );
greater   ( <expression>, <expression> );
pre       ( <expression>, <expression> );
in        ( <expression>, <expression> );
strstr    ( <expression>, <expression> );
pcmp      ( <expression>, <expression> );

Mathematics.

add       ( <expression>, <expression> );
sub       ( <expression>, <expression> );
mult      ( <expression>, <expression> );
div       ( <expression>, <expression> );
mod       ( <expression>, <expression> );
random    ( <expression>, <expression> );

band      ( <expression>, <expression> );
bor       ( <expression>, <expression> );
bxor      ( <expression>, <expression> );

String things.

cat       ( <string>, <string> ) );
word      ( <string>, <word number>  );

Output functions.

out       ( <out string>, <mobtype>, <argument1>, <argument2>, <type> );
numw      ( <string> ) );
strp      ( VD *value, VD *old, VD *new ) );

Game-related functions for mobiles.

do        ( <command1>, [<command2 , , , command5> );
step      (  VD *value ) );
ms        (  VD *astr, VD *bstr ) );

Game-related functions for objects.

os        args( ( void * caller, int type, VD *astr, VD *bstr ) );


Game-related functions for rooms.

None right now



Other game-related functions.

sameroom  ( <value> );
eval      ( <value> );
rndplr    (  );

Site Stats

Snippets: 1791
Codebases: 571