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ISTRY/
LPMUD/MUDLIB/SECURE/
LPMUD/MUDLIB/SECURE/UDP_CMD_/
LPMUD/MUDLIB/SKILLS/
LPMUD/MUDLIB/SKILLS/FIGHTER/
LPMUD/MUDLIB/SKILLS/THIEF/
LPMUD/MUDLIB/USR/
LPMUD/MUDLIB/USR/CREATORS/
LPMUD/MUDLIB/USR/PLAYERS/
             -=[ LPC language basics ]=-

Comments:

Comments are made the same way as in C, /* Comment */. It does
not accept the c++ commenter of '//'



Type Declarations:


LPC has six data types. These types are: status, int, string,
object, mixed, and void. All variables MUST be declared, and
functions SHOULD be declared. There are three basic places
variables can be declared: inside functions, inside a code
block (both of these constitute 'local' variables); and
outside functions ('global' variables).


Example:

int last_integer; 

void example(int integer) {   
  int i;

  i = 2 * integer;
  if(last_integer < integer) {
    string my_name;
    my_name = (string)this_player()->query_name();
    say(my_name+" says: Hi.\n");
  }
  else
    integer = i;
  last_integer = integer;  
}

Example is quite an innane program but is an example of type
declaration. 'last_integer' is a global variable of type
'int'. Its value is known throughout the program, and can be
used and manipulated by any piece of code. 'void' declares
that the function 'example' does not return any value.
'integer' is a 'formal argument' of the function example(). It
has been declared as an 'int' and is treated as a local
variable throughout 'example'. 'i' is a variable declared as
'int', which can be used throughout example(). 'my_name' is
declared as a 'string'. However, it can only be used within
the if(){ } code block. Of note is '(string)this_player()...',
the '(string)' is known as a 'cast'. 

Call_other and casting:

Call_other allows you to call a function in another object.
However, the compiler treats the return value of such a call
as "unknown". So you must declare the type of a call_other by
using a cast. Call_other(object|string,function,arg1,arg2,..)
is equivalant to object->function(arg1,arg2,..).  


MAIN POINTS: Declaration of a variable MUST be done at the 
             head of the file, function, or code block. You 
             should declare all variables and functions. This 
             allows you to find errors in compile time, rather 
             then in run time. Run time errors are always 
             harder to find. The valid declarations are: 
             status, int, string, object, mixed, and void.



Declaring Variables:

 -=[ Type ]=-             -=[ Example of Type ]=-

 status example; /* example is off|on, (1|0), example = 1 */
 int example;    /* example = 5 */
 string example; /* example = "Hi!\n"; */
 object example; /* example = this_player() */
 mixed example;  /* a mixture of int, string, or object */


Declaring Array Variables:

It is important to declare variables that are arrays, as
pointers(*).

 -=[ Type ]=-             -=[ Example of Type ]=-

 int *example;    /* example = ({ 1, 3, 5, 7, }); */
 string *example; /* example = ({ "Bob", "Eric", "Tom", }); */
 object *example; /* example = ({ obj1, obj2, obj3, }); */
 mixed *example;  /* example = ({ 1, "Bob", ({ obj2, }), });



Declaring Functions:

All functions should be declared. They can be declared in the
same way as variables. The type of function declaration
depends upon what the function returns.

  void   /* returns nothing */
  status /* returns 0|1 */
  int    /* returns an int */
  string /* returns a string */
  object /* returns an object */
  mixed  /* returns an int, a string, or an object */
   
eg. A simple monster.

inherit "inherit/monster";

void reset(status arg) {
  if(arg) return;
  set_name("bob");
  set_level(1);
  set_short("Bob the Dwarf");
}  



Declaring Array functions:

Note: If the function returns an array the function should be  
      declared as a pointer.

eg. get an array of weapons that are on a player


object *get_weapon(object player) {
  int i;
  object *inv, *weapons;

  weapons = ({});
  if(!player) player = this_player();
  inv = all_inventory(player);
  for(i = 0; i < sizeof(inv); i++) {
    if(inv[i] -> query_weapon_class()) {
     /* this may be invalid on some muds - see alternative */
      weapons = weapons + ({ inv[i], }); 
    }
  }
  return weapons;
} 


/* an alternative to added to arrays - this would have limits 
   adding arrays with a total of less then 50 elements */

mixed *add_array(mixed *arr1, mixed *arr2) {
  mixed *temp;
  int i, size1, size2;  

  if(!(size1=sizeof(arr1))) {
    if(!sizeof(arr2)) return ({});
    return arr2;
  }
  if(!(size2=sizeof(arr2))) return arr1;
  temp = allocate(size1 + size2);
  for(i = 0; i < sizeof(temp); i++) {
    temp[i] = (i < size1) ? arr1[i]
                          : arr2[i - size1];
  }
  return temp;
}