/usr/share/doc/sludge/SLUDGEDevKitHelp/Introduction_to_SLUDGE_Concepts.html is in sludge-doc 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<TITLE>Introduction to SLUDGE Concepts</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>Introduction to SLUDGE Concepts</h2>
<HR>
<P>
If you've played an adventure game before, you're probably more than aware of all the concepts involved, right? The player controls a character (sometimes, more than one) in some kind of world, consisting of different areas. Along the way the player's character can meet other characters, interact with objects in a variety of ways and carry certain objects with them. Most games also feature conversations of some kind or another. The aim of the game is nearly always to reach the end of the plot which has been set out by the creator(s) of the game by completing a series of puzzles and making the right decisions.
</P>
<P>
Throughout this documentation, various words have specific meanings... although, much of the time, you should be able to fully understand the gist of what's meant without knowing exactly how things work.
</P>
<H3>Objects:</H3>
<P>
An object is a thing. Simple. That character you see on the screen? That's an object. That doorway? That's an object too. That jar of jam you've got in your inventory, that explosion, that daisy, that seagull flying past? They're all objects.
</P>
<P>
To create an object, you first need to define an object type.
</P>
<P>
<pre>objectType phil ("Phil Philson, Juggler Extraordinaire") {
}</pre>
</P>
<P>
The first word has to be "objectType" - because that's what we're creating. The next word is whatever you want to call it... providing the name you choose doesn't use any strange characters or symbols with special meanings. If you just stick to letters you're well and truly safe.
</P>
<P>
Next, in brackets, you have to choose the name by which the object will be known on the screen. Make sure you put it in speech marks, otherwise the compiler will try and turn the name into code and get very confused.
</P>
<P>
So why give each object an internal name <b>and</b> an on-screen name? Well, put it this way... personally, if I had an object called "big fluffy dog called Duke" and wanted to make it do 10 different things, I'd be happier calling it "dog" or "duke" or "dogDuke" in my code.
</P>
<P>
One last thing... those squirly brackets, { and }. They're there so that you can specify different things about each of your objects, such as the colours which are used for text when they speak, the speed at which they walk and, most importantly, what happens when you combine them with other objects. This is all covered in depth elsewhere, but for now, consider the following...
</P>
<P>
<pre>objectType ball ("spotty ball") {
}
objectType phil ("Phil Philson, Juggler Extraordinaire") {
event ball {
say (phil, "Wow, you found my spotty juggling ball!");
}
}</pre>
</P>
<P>
That bit of code creates two objects, called "ball" and "phil". The event inside the second object says what happens when you use the ball object on the phil object. Not too tricky, is it? Each object can contain as many or as few events as you need.
</P>
<H3>Actions:</H3>
<P>
Actions, or verbs, are the concepts such as "Look at", "Talk to", "Pick up", "Walk to" and so on which you will find, in one form or another, in a lot of games. In SLUDGE, guess what? They're just more objects. So, in the same way as we can use the ball object with the phil object in the example above, we can create and use other objects such as lookAt and talkTo.
</P>
<P>
<pre>objectType ball ("spotty ball") {
event lookAt {
say (player, "Looks like it's got a childhood disease.");
}
}
objectType phil ("Phil Philson, Juggler Extraordinaire") {
event lookAt {
say (player, "He's very impressive.");
}
event ball {
say (phil, "Wow, you found my spotty juggling ball!");
}
}</pre>
</P>
<P>
Obviously, objects such as lookAt and talkTo won't be found in crates, pinned to walls or waiting for the bus in your game... but they <b>are</b> just objects, all the same.
</P>
<H3>Functions:</H3>
<P>
Functions look a lot like events. Like events, they're just lists of instructions. For example, if your game has a book which you can read to several people, you don't want to type (or copy and paste) the same thing into a "book" event for each person... what a waste of time and effort, not to mention space. As a rule of thumb, if you want to do something in more than one place... put it in a function.
</P>
<P>
Function definitions start with the word "sub", which is short for subroutine (another name for a function). Next comes the name of the function - again, call it anything you want, but stick to basic characters, like letters. After that, add an empty pair of brackets, and - just like an event - the list of things to do in squirly brackets.
</P>
<P>
<pre>sub readBook () {
say (player, "SLUDGE - A Beginner's Guide.");
say (player, "SLUDGE is a programming language.");
say (player, "With it, you can write your own adventure games.");
}</pre>
</P>
<P>
To call a function - that is, to run the code which it contains - just type its name in another function, or in an event. For example, you may want to call the readBook function, above, when the player looks at it (combining the lookAt and sludgeBook objects) and also when the player shows it to someone (combining the sludgeBook and phil objects).
</P>
<P>
<pre>objectType sludgeBook ("book about the wonders of SLUDGE") {
event lookAt {
readBook ();
say (player, "...it goes on like that for 400 pages.");
}
}
objectType phil ("Phil Philson, Juggler Extraordinaire") {
event sludgeBook {
say (player, "I'm going to read you this book.");
readBook ();
say (phil, "Stop! Please stop!");
}
}</pre>
</P>
<P>
When you call a function, SLUDGE pauses the current event or function until the code you've called is all finished. So, if you combine the sludgeBook and phil objects, you'll be shown the following scene...
</P>
<P>
<b>Player's character: </b>I'm going to read you this book.
</P>
<P>
<b>Player's character: </b>SLUDGE - A Beginner's Guide.
</P>
<P>
<b>Player's character: </b>SLUDGE is a programming language.
</P>
<P>
<b>Player's character: </b>With it, you can write your own adventure games.
</P>
<P>
<b>Phil: </b>Stop! Please stop!
</P>
<P>
You may be wondering what those empty brackets are for. Well, you can pass any number of values into a function, and use them inside. This is, however, beyond the scope of this quick introduction.
</P>
<P>
<H3>Global and local variables:</H3>
</P>
<P>
If you've programmed before, you can skip this paragraph. If you're new to programming, you probably won't know much about variables, if anything... so here goes. You can think of a variable as a whiteboard... you can write things onto it, and you can read from it. Why a whiteboard, and not a bit of paper? Because it's reusable. When you write something new onto it, whatever was there before is wiped - and you can use it as much as you want. And yes, that means it can only hold one thing at once.*
</P>
<P>
* = Normally
</P>
<P>
Right - the people who'd heard of variables before, welcome back. Any SLUDGE variable can hold any type of information (there are some languages where you need one type of variable to hold a number, a different type to hold a sentence, a different type to hold a noise and so on). You can create variables inside or outside of events and functions, and in either case you do it by saying:
</P>
<P>
<pre>var variableNameGoesHere;</pre>
</P>
<P>
If you create a variable in between two functions, two object types, a function and an object type... OK, you get the idea... it's what's known as a global variable. It will be created when your game starts, and will last until your game stops. Any of your functions and events can look at and change it.
</P>
<P>
If you create a variable inside a function or an event, it's what's known as a local variable. It's only created when the function or event starts, and disappears when the function or event comes to an end. That means, if you run the same function twice, the value of the variable is reset the second time the function starts. Variables inside one function are separate from variables inside another - one function can't look at or change another function's variables.
</P>
<P>
The simplest way to give a variable a value is to use the equals sign, which means "gets changed to". So...
</P>
<P>
<pre>sub doNumberStuff () {
var num;
num = 1;
say (player, num);
num = 2;
say (player, num);
num = num - 5;
say (player, num);
}</pre>
</P>
<P>
...would make the "player" object say "1", "2" and (at this point, "num" becomes its old value minus 5) "-3".
</P>
<P>
There are plenty of other built-in mathematical and logical operations which can be performed on variables, too... from adding and subtracting, past multiplication and division all the way to binary ands and ors.
</P>
<H3>Rooms:</H3>
<P>
In SLUDGE, there's no such thing as a room as such. Why bother? Walking into a new room, after all, means little more than putting characters in certain places on the screen and changing the background image. It's just a list of instructions. In SLUDGE, every room is just a function.
</P>
<P>
OK, now this is where we start to see a few commands we haven't run into yet... but you should be able to work out what they do.
</P>
<P>
<pre>sub kitchen () {
addOverlay ('kitchenPicture.tga', 0, 0);
addCharacter (player, 320, 400, playerCostume);
}</pre>
</P>
<P>
How do we go from one room into the next? Personally, I'd suggest a doorway. That's something with which you'll want to interact... so it's an object.
</P>
<P>
<pre>objectType kitchenDoor ("door into hallway") {
event walkTo {
gotoRoom (hallway);
}
}</pre>
</P>
<P>
(Of course, this will only work if you're using an interface which uses a walkTo object and has a gotoRoom function. If you're basing your game on a different interface, take a look at the door objects which exist already, to see how they've been coded.)
</P>
<P>
Hang on... a doorway isn't a character! It's something we've drawn on the background image already! All we want to do is set up an area of the screen which will be labelled "door into hallway" when the mouse points at it. That's something known as a screen region in SLUDGE, and we can add one like this...
</P>
<P>
<pre>sub kitchen () {
addOverlay ('kitchenPicture.tga', 0, 0);
addCharacter (player, 320, 400, playerCostume);
addScreenRegion (kitchenDoor, 50, 50, 150, 350, 100, 370, NORTH);
}</pre>
</P>
<P>
The numbers here are in pairs... the first pair (50, 50) specifies the top left corner of the interactive region. The second pair (150, 350) specifies the bottom right corner of the region. The final pair (100, 370) specifies where a character will try and stand if (s)he's told to walk to the object in question.
</P>
<H3>And away you go:</H3>
<P>
That's pretty much all the basics you need to get started. You should now be able to understand much of the room and object code in any example project you may have around... and even start changing bits.
</P>
<P>
Bear in mind that a lot of functions - such as gotoRoom, mentioned above, and any inventory management and interactive conversation code - won't be described in this help file because they're not part of SLUDGE... they're part of the specific project. By all means, find and take a look at the code, but don't expect to follow it all just yet.
</P>
<P>
Good luck!
</P>
<H3>See also:</H3>
<P>
<a href="Overview__Creating_a_Game.html">Overview: Creating a Game</a>
</P>
<P>
<a href="SLUDGE_Language_Reference_Manual.html">SLUDGE Language Reference Manual</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>
|