File: Object_Types_and_Events.html

package info (click to toggle)
sludge 2.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,912 kB
  • sloc: cpp: 32,441; sh: 1,237; xml: 874; makefile: 682
file content (165 lines) | stat: -rwxr-xr-x 5,179 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<TITLE>Object Types and Events</TITLE>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<BODY>
<HR>
<div align="center"><img id="headerGraphic" src="images/sludge300.png" alt="SLUDGE"/></div>
<h2>Object Types and Events</h2>
<HR>


<P>
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: 
</P>

<P>
<pre>objectType ego (&quot;Egor the ego&quot;) {
}

objectType lookAt (&quot;Look at&quot;) {
}

objectType pickUp (&quot;Pick up&quot;) {
}

objectType hat (&quot;old battered top hat&quot;) {
}</pre>
</P>

<P>
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 <a href="callEvent.html">callEvent</a> function.
</P>

<P>
<pre>objectType box (&quot;box&quot;) {
   event lookAt {
      say (ego, &quot;It's full of junk, none of which looks useful.&quot;);
   }
   event pickUp {
      say (ego, &quot;It looks too heavy to lift.&quot;);
   }
}</pre>
</P>

<P>
With the above object type definitions, if a function was to call:
</P>

<P>
<pre>callEvent (lookAt, box);</pre>
</P>

<P>
...the ego character would say the line &quot;It's full of junk, none of which looks useful.&quot;
</P>

<P>
<H3>Elements of an objectType definition:</H3>

</P>

<P>
Here are all the different (optional) parts of an object type...
</P>

<P>
<pre>speechColour 128, 128, 128;</pre>
</P>

<P>
Use this to specify the colour in which the object will &quot;speak&quot;. You can use the reserved word speechColor too, for our overseas friends - it does exactly the same thing.
</P>

<P>
<pre>speechGap 8;</pre>
</P>

<P>
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.
</P>

<P>
<pre>walkSpeed 5;</pre>
</P>

<P>
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 <a href="setCharacterWalkSpeed.html">setCharacterWalkSpeed</a> function.) The default is 5.
</P>

<P>
<pre>spinSpeed 45;</pre>
</P>

<P>
Specify how many degrees the object type can turn per frame when used as a character, either walking or told to turn using the <a href="turnCharacter_and_spinCharacter.html">spinCharacter</a> 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 <a href="setCharacterSpinSpeed.html">setCharacterSpinSpeed</a> function.) The default value is 0.
</P>

<P>
<pre>wrapSpeech 40;</pre>
</P>

<P>
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.
</P>

<P>
<pre>event someOtherObject {
   # Code here
}</pre>
</P>

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

<P>
<pre>event someOtherObject2 = someOtherSub;</pre>
</P>

<P>
Existing functions can be reused... see <a href="Reusing_Code_for_or_from_Events.html">Reusing Code for or from Events</a> for details.
</P>

<P>
<pre>var someMemberVariable = 100;

sub someMemberFunction () { ... }</pre>
</P>

<P>
Yes, since SLUDGE v1.1, your object types can have member variables and functions... see <a href="Member_Variables_and_Member_Functions.html">Member Variables and Member Functions</a> for details.
</P>

<P>
<pre>flag IS_TOO_HEAVY_TO_CARRY;

flags IS_TOO_HEAVY_TO_CARRY, ALIVE, NOT_AFRAID_OF_SPIDERS;</pre>
</P>

<P>
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 <a href="hasFlag.html">hasFlag</a> 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.
</P>

<H3>More on this subject:</H3>

<P>
<a href="Setting_Default_Events.html">Setting Default Events</a>
</P>

<P>
<a href="Object_Types_as_Characters.html">Object Types as Characters</a>
</P>

<P>
<a href="Object_Types_as_Screen_Regions.html">Object Types as Screen Regions</a>
</P>

<P class="copyright-notice">SLUDGE and this SLUDGE documentation are <A HREF="Copyright.html">copyright</A> Hungry Software and contributors 2000-2012
</P>

<HR>
</BODY>
</html>