SLUDGE

Using Constants in SLUDGE


The SLUDGE compiler knows several constants already, such as NULL and FALSE (both of which are just other ways of saying 0), TRUE (which is another way of saying 1) and so on. Should you want to define your own custom constant values in SLUDGE, you can do this using definition files (with the extension ".SLD"). Constant values cannot be defined in SLUDGE scripts.

To create and add a definition file to your project, choose the "Add" button below the "Files in project" box in the SLUDGE Project Manager program. In the dialog box which appears, select the file type "SLUDGE definition files (*.SLD)" and type a name for the file you want to create.

When you've created the file, select it from the list and press the "Edit" button. Put one definition on each line. For example...

AUTHORNAME = "Tim"
YEAR = 2002
NEXTYEAR = (YEAR + 1)

Should a definitions file contain the above lines, whenever the SLUDGE compiler finds the word AUTHORNAME it will think it's found the word Tim in speech marks; whenever it finds the word YEAR it will think it's found the number 2002; whenever it finds the word NEXTYEAR it will think it's found the expression YEAR + 1 in brackets (the YEAR part of which will then be expanded as above).

Any spaces either side of the separating equals sign are disregarded. Blank lines and lines starting with a "#" are ignored.

What you can't do:

Only complete expressions can be used as constants. You can't, for example, say:

MINUS = -

...and then expect the following code to work:

var t = 100 MINUS 4;

But then why would you want to?