Difference between revisions of "Manual:DIL Examples"

From DikuMUD Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 +
= This Section =
 +
I put this section in here because while many programmers already know most of this inherently, many casual mudders have the curiosity and want to start building but don't know where to start with dil and the manual can be a bit overwhelming.
 +
So this is a compilation of the most frequently asked questions and overall stumbling blocks we've seen for new coders. Hopefully it helps.
 
= Construction =
 
= Construction =
 
Every DIL program has the following structure:<br>
 
Every DIL program has the following structure:<br>
Line 9: Line 12:
 
</nowiki><br>
 
</nowiki><br>
  
It's nice to think about dils in different categories.
 
  
 
Every dil must run on an object. That object is always going to be 'self' to the program.
 
Every dil must run on an object. That object is always going to be 'self' to the program.
Line 20: Line 22:
 
Keeping this in mind will help with your program's construction. You can also use dot notation to reference objects relative to the dil or the objects it interacts with.
 
Keeping this in mind will help with your program's construction. You can also use dot notation to reference objects relative to the dil or the objects it interacts with.
 
Take <code>self.outside</code> and we'll look at it from each of the object types.
 
Take <code>self.outside</code> and we'll look at it from each of the object types.
 +
 
=== Dil On an Object ===
 
=== Dil On an Object ===
 
So let's say this particular DIL lives on a gem. The gem says nice things to you when it's held.  
 
So let's say this particular DIL lives on a gem. The gem says nice things to you when it's held.  
Line 42: Line 45:
 
* self.outside varies by where the object is. If it's in a bag, self.outside = the bag.  
 
* self.outside varies by where the object is. If it's in a bag, self.outside = the bag.  
 
** self. outside could also be an NPC if it's inside a mob. It could be a player. Remember, people can go in containers too!
 
** self. outside could also be an NPC if it's inside a mob. It could be a player. Remember, people can go in containers too!
 +
* self.outside.outside.inside is a even a possibility!
 +
  
 
=== DIL on an NPC ===
 
=== DIL on an NPC ===

Revision as of 17:36, 1 June 2020

This Section

I put this section in here because while many programmers already know most of this inherently, many casual mudders have the curiosity and want to start building but don't know where to start with dil and the manual can be a bit overwhelming. So this is a compilation of the most frequently asked questions and overall stumbling blocks we've seen for new coders. Hopefully it helps.

Construction

Every DIL program has the following structure:

 dilbegin programname();
 var
 code
 {}
 dilend


Every dil must run on an object. That object is always going to be 'self' to the program. It will be running from one of the following things:

  • A room
  • A mobile (npc)
  • A player
  • An object (thing)

Keeping this in mind will help with your program's construction. You can also use dot notation to reference objects relative to the dil or the objects it interacts with. Take self.outside and we'll look at it from each of the object types.

Dil On an Object

So let's say this particular DIL lives on a gem. The gem says nice things to you when it's held. Considerations:
Does it speak when you're incapacitated? Meditating? Fighting? Does it speak when you're invisible? Can other people hear it? How often can it speak?

dilbegin gem_speak();
          var
          code 
          {
             heartbeat := 90*PULSE_SEC; //every 90 seconds. 
             :start:
             wait(SFB_TICK, TRUE and self.outside.type == UNIT_ST_PC and self.equip);
             act("$1n says 'You look lovely today!'", A_ALWAYS, self.outside, self, null, TO_CHAR);
             goto start;
          }
          dilend

In this example:

  • self.outside varies by where the object is. If it's in a bag, self.outside = the bag.
    • self. outside could also be an NPC if it's inside a mob. It could be a player. Remember, people can go in containers too!
  • self.outside.outside.inside is a even a possibility!


DIL on an NPC

So this particular DIL will live on a NPC or mobile. Perhaps it will say "Greetings" every time an actual player enters the room.

dilbegin hi();
         var
         code
         {
          :start: 
          wait(SFB_DONE, command(CMD_AUTO_ENTER) and activator.type == UNIT_ST_PC);
          exec("say Hello, "+ activator.name +"!", self);
          goto start;
         }
         dilend

In this example:

  • self.outside = the room the NPC is in.
  • self.inside = the NPC's inventory.