SLUDGE

Object Types and Events


An object type is a structure which is created outside of any functions and contains the default name for the object when it appears on screen. Actions are also created in this way. For example:

objectType ego ("Egor the ego") {
}

objectType lookAt ("Look at") {
}

objectType pickUp ("Pick up") {
}

objectType hat ("old battered top hat") {
}

Object types can also specify chunks of code which should be run when the object type is combined with another object type using the built-in callEvent function.

objectType box ("box") {
   event lookAt {
      say (ego, "It's full of junk, none of which looks useful.");
   }
   event pickUp {
      say (ego, "It looks too heavy to lift.");
   }
}

With the above object type definitions, if a function was to call:

callEvent (lookAt, box);

...the ego character would say the line "It's full of junk, none of which looks useful."

Elements of an objectType definition:

Here are all the different (optional) parts of an object type...

speechColour 128, 128, 128;

Use this to specify the colour in which the object will "speak". You can use the reserved word speechColor too, for our overseas friends - it does exactly the same thing.

speechGap 8;

This sets the distance, in pixels, between the top of an object and the text which appears on the screen when it talks. Useful if you're using a character to animate a mouth in a close-up, for example, but still want speech text to appear over the top of the whole face. The default is 8.

walkSpeed 5;

Use this to set the default walk speed for a particular object type, should it be used as a character. 1 is the slowest possible, and numbers into (or higher than) double figures are pretty darn speedy. (Once an object type has been added to a scene, its walking speed can be changed on the fly using the setCharacterWalkSpeed function.) The default is 5.

spinSpeed 45;

Specify how many degrees the object type can turn per frame when used as a character, either walking or told to turn using the spinCharacter command. A value of 0 means that the character's spin speed is calculated automatically, based on the number of directions in the character's current costume. (A character's spin speed can also be changed on the fly using the setCharacterSpinSpeed function.) The default value is 0.

wrapSpeech 40;

Use this to change the number of characters which can be displayed on the same line when the object type speaks. The default value is 30.

event someOtherObject {
   # Code here
}

The code which is called when the object is combined with another object type - see above.

event someOtherObject2 = someOtherSub;

Existing functions can be reused... see Reusing Code for or from Events for details.

var someMemberVariable = 100;

sub someMemberFunction () { ... }

Yes, since SLUDGE v1.1, your object types can have member variables and functions... see Member Variables and Member Functions for details.

flag IS_TOO_HEAVY_TO_CARRY;

flags IS_TOO_HEAVY_TO_CARRY, ALIVE, NOT_AFRAID_OF_SPIDERS;

SLUDGE v1.4 added the concept of object flags. Give your objects any flag or flags you want - to create a new flag, just start talking about it in one of your object types. You can then check whether a particular object type has a particular flag set using the hasFlag function. You can have a maximum of 16 flags in your game. The words "flag" and "flags" are interchangable - both are provided for code readability.

More on this subject:

Setting Default Events

Object Types as Characters

Object Types as Screen Regions