Some Basic Info you Need to Know

From Hungrysoftware

This page contains knowledge that any self-respecting SLUDGE user can't be without. That and important information that isn't really worthy of it's own page...

Comments Inside Code

If you're going to look at examples and source code for SLUDGE projects, then the odds are that you will want to know what particular pieces of code are doing. This is where comments come in handy. Comments are totally ignored by the SLUDGE compiler, so you can type what you like inside your source code and it won't appear inside your game.

In SLUDGE, comments are made by placing the # symbol at the start of the line. Unfortunately, there is currently no way to make comment blocks, so each line must be commented manually.

   #This line can say whatever it likes
   pause (5);
   #The line above will pause the active sub for 5 frames.

Commenting is useful not just for making code easier to interpret, but can also be great for making previous code not execute if you want to change it and try something different. It's far better than removing it and then trying to remember what it was when you want to use it again.

Strings and File Handlers

What's the difference between 2 and "2"? Not much you may think. But you'd be wrong. 2 + 2 is 4, but "2" + "2" just isn't valid.

In programming languages, the computer treats the number 2, and the "letter" 2 very differently. The number (or value) 2 can have all the usual arithmetic operations performed on it. The letter 2 can't, mainly because it's just a graphical ASCII-character representation of the number 2, it could be B for all the computer cares. So how does the computer know the difference between the two? It doesn't, you need to tell it. Computers are dumb like that, but that probably explains why they haven't taken over the world and enslaved us all yet; too busy trying to divide sentences.

So SLUDGE needs you to tell it what's what. Anything contained within double quotation marks "like so" is what's known as a string. Strings don't really do much, but they are incredibly useful. Strings are needed to give objects names in the game, or contain what your character is going to say. If something is a string, then SLUDGE won't mistake it for a piece of code.

Things placed inside single quotation marks 'like so' are known as file handlers. This is used when you want to tell SLUDGE to look for a particular file on your computer, most commonly used when loading images and sounds.

   addOverlay ('rooms/garden/room.tga', 0, 0);
   #The function above will add rooms/garden/room.tga as a background image.

The init () Sub

So you've made a game. The question is, where in the world does SLUDGE start when it runs your game? You certainly didn't see an option inside the project manager telling you where to begin your program. The answer is simple.

   sub init () {
   #Anything placed here will be executed when the game runs
   }

The sub init () sub is the first place SLUDGE looks when running a game (well, except for an ini file, but we'll ignore that for now...). The contents of the init sub needs to tell your game to do something, or nothing will happen. A common starting place is to load up a main menu and set up a keyboard handler or something for the mouse to do (see User interaction).

Personal tools