Next Previous Contents

1. String Functions

1.1 Compare strings with Case

Function: integer strcmp( s1:string, s2:string) ;

s1

first string

s2

second string

returns

-1

if s1 < s2

0

if s1 = s2

1

if s1 > s2

This allows you to compare strings with case sensitivity in place. If you don't care about the case of the string use the normal '==' '>', '<', '<=', '>=', symbols.

example:


 

if (strcmp("I Care about Capitals",s2)==0))
        {
        sendtext ("You care I can see.&n",self);
        quit;
        }
        
        

1.2 Compare partial strings with Case

Function: integer strcmp( s1:string, s2:string l :integer) ;

s1

first string

s2

second string

l

amount of significant digits to compare

returns

-1

if s1 < s2

0

if s1 = s2

1

if s1 > s2

This allows you to compare strings with case sensitivity in place and it allows you to choose how much of the strings are compared.

example:


 

if (strcmp("Mark Carper",s2,4)==0))
        {
        sendtext ("Hi Mark hows it going?&n",self);
                quit;
        }
        
        

1.3 Delete a String file

Function: integer delstr( filename : string ) ;

filename

The name of the String file to be deleted

Return

Returns an integer TRUE if deleted FALSE if not

The delstr is used to delete files that are used with the 'loadstr' and 'savestr' functions. The delstr function will only delete files that each individual Zone has access to which is set up in the Zonelist file in the VME etc directory.

Example:



dilbegin news|del ("arg : string /*filename to be deleted);
var
        ret:integer;/*to hold the return value if deleted or not*/
code
{
ret:= delstr("news.txt");
if (!ret)
        {
        log ("File not deleted.");
        quit;
        }

sendtext ("News file deleted[&]n",self);
quit;/*dil delete routine done
}
dilend

See Also Load String file and Save String file

1.4 Insert a string into a stringlist or integer into an intlist by index

Function: insert( sl : <stringlist or intlist>, i : integer, s : string ) ;

sl

the stringlist or intlist you are inserting to

i

the index where you want to insert the string

s

the string you want to insert

This function allows you to insert a string in a stringlist or intlist with out re-writing the entire stringlist or intlist to do it. The following Dil will add a string in order to a stringlist.

Example:



dilbegin stringlist add_in_order (sl:stringlist,s:string);
var
 i:integer;
 ln:integer;
code
{
if (length(sl)==0)
 {
 addstring (sl,s);
 return (sl);
 }

ln:=length(s);
i:=0;
while (i<ln)
 {
 if (length(sl.[i]) <=ln)
  {
  insert (sl,i,s);
 return(sl);
 }
 i:=i+1;
 }

addstring (sl,s);
return (sl);
}
dilend

1.5 Remove a string from a stringlist or an integer from an intlist by index

Function: remove( sl : stringlist, i : integer ) ;

sl

the stringlist you are removing from

i

the index you want to remove

This function allows you to remove a string from a stringlist with out leaving a blank spot in the stringlist.

Example: remove (sl, i);

1.6 Get a listing of the String Directory

Function: stringlist strdir( match : string ) ;

match

The wild card file you want to match or '*' for all.

return

a Stringlist with all the filenames that match the 'match' argument.

The 'match' argument uses the same wild cards as the Linux 'ls' command so the following will work.

*

Match any character or group of characters

?

Match one of any character

[...]

Match one of a set of characters

Example:



"corpse*" matches:  corpse.10938 corpse.whistler corpseofwhistler ...
"corpse?" matches corpse1 corpses corpse5 ...
"[abc]*" matches ability about cost back ...
"[a-z]*" about zoo man father ...
"start[nm]end" matches startnend startmend

Example DIL:



dilbegin wanted ();
var
        wantedlist:stringlist;
        templist:stringlist;
        i:integer;
        ln:integer;
code
{

        wantedlist := strdir ("dead*");

                i := 0;
                ln := length (wantedlist);

        while (i < ln )
                {
                templist := split (wantedlist.[i],".");
                sendtext (templist.[1]+" wanted dead!&n",self);
                i:=i+1;
                }

quit;
}
dilend


The previous DIL would be an example of a command to check the wanted dead players on the VME if you saved the files with the first word being 'dead' and separated it with a '.' and the players name. For example if 'whistler' was wanted dead the file name would be 'dead.whistler'

1.7 Check a file size

Function: integer filesize ( filename :string);

filename

file you want to check

return

a file size in bites 0 if no file

Example DIL:



dilbegin notebook ();
code
{
        ns := filesize (self.name+"notebook");
        if ( ns >500000)
        {
                sendtext ("Your notebook is full.&n",self);
                quit;
        }
        else if ( ns > 250000)
        {
                sendtext ("Your notebook is more than half full.&n",self);
                quit;
        }
        else if (ns >125000)
        {
                sendtext ("Your Notebook is only 1/4 full.&n",self);
                quit;
        }
        else if (ns >0)
        {
                sendtext ("Your notebook is less than 1/4 full.&n",self);
                quit;
        }
        else
        {
                sendtext ("You don't have anything in your Notebook.&n",self);
                quit;
        }

}
dilend

The previous DIL example shows how you could use the 'filesize' instruction to check the size of a player stored notebook.

1.8 Edit a String field

Function: beginedit ( u : unitptr);

u

the PC unit doing the editing

return

When done editing it returns SFB_EDIT and activator is set to PC

The 'BEGINEDIT' function sets a PC into editing mode. while in edit mode the PC field 'editing is set to true. Once the PC is done editing a 'SFB_EDIT' message is sent to the unit editing to continue on with the DIL. If for some reason the PC needs to break out of the editor before it is done editing then the Dil needs to call the 'killedit' function interrupt editing before done

example:



dilbegin edextra ();
var
        temp:string;
code
{
        beginedit (self);
        wait(SFB_EDIT,self==activator) ;
        temp:=textformat(argument);
        addextra (self.extra,"general",temp);
        quit;
}
dilend

The previous DIL is an example of how you could make a command to set the general extra which is the characters description when you do 'look player'

1.9 interrupt editing before done"

Function: killedit ;

This function is used to kill the editor on a PC if it needs to stop editing before the PC is done editing. An example of when this is needed is when a player is killed while editing or is transfered away from a place where he was editing. You can let them finish but it may be wierd for a person to finish posting in one room while in another.

Example



dilbegin editextra (arg:string);
code
{
interrupt (SFB_DEAD,self==activator,int_quit);
        beginedit (self);
        wait(SFB_EDIT,self==activator) ;
        temp := textformat(argument);
addextra (self.outside.extra ,{"graphitee"},temp);
quit;
:int_quit:
killedit;
quit;
}
dilend

1.10 Return left portion of String

Function: string left ( o : string, l : integer );

o

the original string to be parsed

l

The amount of characters to parse out

return

the left portion of the string with length l

This function parses the string passed to it and returns the number of characters defined in its second argument.

Example: "short" := left ("shorten me",5);

Example:



dilbegin aware describe (arg:string);
var
        side:string;
        oneword:stringlist;
        location:string;
        ln:integer;
        args:stringlist;
        temp:string;
        i:integer;
        x:extraptr;
code
{
        if (self.type!=UNIT_ST_PC)
                quit;
        if (self.position <POSITION_SLEEPING)
        {
                act ("Recover first and then you can describe your body parts.",
                        A_ALWAYS,self,null,null,TO_CHAR);
                quit;
        }

        args:=getwords(arg);
        ln:=length(args);
        if ((ln<1) or (ln>2))
        {
                sendtext ("No such location to describe.",self);
                quit;
        }
        else if (ln>1)
                goto two_word;

        :one_word:

        if ((arg==left("help",length(arg))) or
                (arg==""))
                goto hlp_dscr;

        oneword := {"arms","butt","ears","eyes","face","feet","General","hair","hands",
                "head","legs","mouth","neck","nose","nostrils","teeth","toes","tongue"};

        i := 0;
        ln := length(args.[0]);
        temp:="ERROR";
        while (i<18)
        {
                if (args.[0]==left(oneword.[i],ln))
                {
                        temp := oneword.[i];
                        break;
                }
                i := i+1;
        }

        if (temp=="ERROR")
        {
                sendtext ("No such location to describe.",self);
                quit;
        }

        goto describe;

        :two_word:

        oneword := {"arm","leg","foot","hand","eye","ear"};
        temp := "ERROR";
        ln := length(args.[0]);
        if (args.[0] == left("left",ln))
                side:="left";
        else if (args.[0] == left("right",ln))
                side:="right";
        else
        {
                sendtext ("No such location to describe.",self);
                quit;
        }

        i := 0;
        while (i<6)
        {
                if (args.[1]==left(oneword.[i],ln))
                {
                        temp := oneword.[i];
                        break;
                }
                i := i+1;
        }

        if (temp=="ERROR")
        {
                sendtext ("No such location to describe.",self);
                quit;
        }

        temp := side+" "+temp;

        :describe:
        if (temp=="General")
                location := "";
        else
                location := temp;

        x := location in self.extra;
        if (x!=null)
                if (location=="")
                        sendtext("your Current description for your body is:  &n"+x.descr+"&n",self);
                else
                        sendtext("your Current description for your "+location+"is:  &n"+x.descr+"&n",self);


        if (location=="")
                sendtext ("Enter a text you would like others to see when they look at your body.&n",self);
        else
                sendtext ("Enter a text you would like others to see when they look at your "+location+".&n",self);

        beginedit (self);
        wait(SFB_EDIT,self==activator) ;
        temp := textformat(argument);
        oneword:={""};
        subextra(self.extra,location);
        addstring (oneword, location);
        addextra (self.extra,oneword,temp);
        sendtext ("Description added.&n",self);
        quit;

        :hlp_dscr:

        sendtext ("&nCorrect usage of 'describe':&n&n",self);
        sendtext ("describe <position>&n&n",self);
        sendtext("<position> being one of the following:&n&n",self);
        sendtext( "arms        butt        ears        eyes&n"+
                                                "face        feet        General     hair&n"+
                                                "hands       head        left arm    left leg&n"+
                                                "left foot   left hand   left eye    left ear&n"+
                                                "legs        mouth       neck        nose&n"+
                                                "nostrils    right arm   right leg   right foot&n"+
                                         "right hand  right eye   right ear   teeth&n"+
                                        "toes        tounge&n&n",self);
        sendtext ("Example:  &n&n",self);
        sendtext ("describe left leg&n",self);
        quit;
}
dilend

1.11 Return Middle portion of String

Function: string mid ( o : string, s : integer, e : integer );

o

the original string to be parsed

s

The starting point of the string to be parsed out

e

the ending point of the string to be parsed out

return

the portion of the string defined by the 's' and 'e' values

This function parses the string passed to it and returns the portion of the string defined by the start value and the end value that is also passed to the function.

Example: "rock" := mid ("sprocket",3,6);

1.12 Load a String file

Function: integer loadstr( filename : string , buff : string );

filename

The name of the string file to be loaded

buff

The string that you wish to read the file contents into

Return

FILE_LOADED, FILE_NOT_FOUND, FILE_OUT_OF_MEMORY, or FILE_TO_LARGE

Loadstr is used to load strings from disk that were saved either by savestr or any text editor. The 'loadstr' is perfect for operations such as on-line edited newspaper, a lottery where the tickets are sold to players, creating smarter NPC's that can remember through reboots who they are hunting, Dil based teachers, message boards, mail system, news command., zone or room based help, competition boards, and much much more.

Disk access is always slow. attempt to keep file sizes to a minimum for quick loading. Otherwise you might cause serious delays on the server.

Example:



dilbegin news_load ();
var
        ret:integer;/*to hold the return value if loaded or not*/
        buff:string;/*to hold the loaded string*/
code
{
ret:= loadstr("news.txt",buff);
if (!ret)
        {
        log ("File not read.");
        quit;
        }

sendtext(buff+"[&]n",self);
quit;/*dil load routine done destroy self.*/
}
dilend

See Also Delete a String file and Save String file

1.13 String Comparison Operators

Operators: <= >= < >

All of these operators can now support sorting strings. They are non-case sensitive which means they don't care if it has capitals or not it sorts them the same.

1.14 Replace a sub String with another String

Function: string replace( t :string, n : string, o : string);

t

the target string you want to replace

n

what you want to replace the target with

o

the original string

return

the string with the old string replaced by the new string

This function replaces all occurences of a string in another string with a new string.

Example:

"Jafar %t% %l%" := replace(%n%,pc.name,"%n% %t% %l%"); "Jafar the human %l%" := replace(%t%,pc.title,"Jafar %t% %l%"); "Jafar the human 1" := replace(%l%,itoa(pc.vlevel),"Jafar the human %l%");

1.15 Return Right portion of String

Function: string right ( o : string, r : integer );

o

the original string to be parsed

r

The amount of characters to parse out

return

the right portion of the string with length r

This function parses the string passed to it and returns the number of characters from the right defined in its second argument.

Example: "Easy" := right ("This is Easy",4);

1.16 Save a String file

Function: integer savestr( filename : string , buff : string , wa :string);

filename

The name of the String file to save the String to

buff

The String you wish to save into the file

wa

Write or append

Return

FILE_SAVED, FILE_NOT_SAVED, FILE_NOT_CREATED, or FILE_ILEGAL_OPP

Savestr is used to save strings to disk to be loaded later by the 'load' function. The 'savestr' and 'Loadstr' is perfect for operations such as on-line edited newspaper, a lottery where the tickets are sold to players, creating smarter NPC's that can remember through reboots who they are hunting, Dil based teachers, message boards, mail system, news command., zone or room based help, competition boards, and much much more.

Note:The append/write argument must be in lower case and can only be a 'w' or a 'a' surrounded by '"'. If the argument is a 'w' it will over write any string file by that name. If the argument is 'a' it will append to the file by that name.

Disk access is always slow. If you use loadstr on a continuous basis always attempt to keep file sizes to a minimum for quick loading. Otherwise you might cause serious delays on the server.

Example:



dilbegin news_save (arg:string  /*for saving*/);
var
        ret:integer;/*to hold the return value if saved or not*/
code
{
ret:= savestr("news.txt",arg,"w");
if (!ret)
        {
        log ("File not wrote");
        quit;
        }

sendtext("New news file wrote.[&]n",self);
quit;/*dil save routine done destroy self.*/
}
dilend

See Also Delete a String file and Load a String file

1.17 Change Case of String

Change to Lower Case

Function: string tolower ( s : string );

s

String to lower case

return

the string passed in lower cased

This function returns a copy of the string passed in but with out capitals.

Example: "hello!" := tolower("HELLO!");

Change to UPper Case

Function: string toupper ( s : string );

s

String to lower case

return

the string passed in lower cased

This function returns a copy of the string passed in with all characters changed to be capitalized.

Example: "HELLO!" := toupper ("hello!");

1.18 Create Zone Logs

Function: flog (filename : string, s : string, wa : string );

filename

The Filename of the file to appear in the log directory.

s

The string to be logged.

wa

Write or Append

The 'flog' function allows you to split up your logs in the log directory so that you don't end up with everything in the main vme.log.

Note:The append/write argument must be in lower case and can only be a 'w' or a 'a' surrounded by '"'. If the argument is a 'w' it will over write any log file by that name. If the argument is 'a' it will append to the file by that name.

Example:



dilbegin zonelog (s:string);
code
{
flog (self.zonidx+".log",s,"a");
return;
}
dilend

The previous DIL function will work in any zone to log to a file with that zones name each zone could use it to keep zone logs separated.


Next Previous Contents