Difference between revisions of "Manual:DIL Examples"

From DikuMUD Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
= General Considerations =
 
= General Considerations =
 
Every DIL program has the following structure:<br>
 
Every DIL program has the following structure:<br>
  <nowiki>dilbegin programname();
+
  <nowiki>
 +
dilbegin programname();
 
  var
 
  var
 
  code
 
  code
 
  {}
 
  {}
  dilend</nowiki><br>
+
  dilend
 +
</nowiki><br>
  
 
It's nice to think about dils in different categories.
 
It's nice to think about dils in different categories.
Line 18: Line 20:
 
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 ===
 +
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?
 +
 +
<code>dilbegin gem_speak();
 +
var
 +
 
 +
code {
 +
heartbeat := 90*PULSE_SEC; //every 90 seconds.
 +
:start:
 +
wait(SFB_TICK, TRUE and self.outside.type == UNIT_ST_PC);
 +
act("$1n says 'You look lovely today!'", A_ALWAYS, self.outside, self, null, TO_CHAR);
 +
goto start;
 +
}
 +
dilend</code>

Revision as of 23:12, 31 May 2020

General Considerations

Every DIL program has the following structure:

 dilbegin programname();
 var
 code
 {}
 dilend

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. 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?

dilbegin gem_speak();

var

code { heartbeat := 90*PULSE_SEC; //every 90 seconds.

start:

wait(SFB_TICK, TRUE and self.outside.type == UNIT_ST_PC); act("$1n says 'You look lovely today!'", A_ALWAYS, self.outside, self, null, TO_CHAR); goto start; } dilend