SLUDGE

File Handling


If you've used C++ or Perl, you'll be used to the idea that text in double quotes "like this" and text in single quotes 'like this' can have different meanings. In SLUDGE, strings in single quotes are interpreted as file handles. That is, during compilation, instead of including the text in your finished game the SLUDGE compiler includes the file itself. Therefore, "Hello.tga" represents the string Hello.tga (which can then be spoken, printed on the screen and so on). Alternatively, 'Hello.tga' represents the contents of the file Hello.tga (which can then be drawn on the screen or - for other file types - played as a sound or a piece of music, set as the new floor and so on).

Files which are referenced more than once are only included in your finished game in one place. If you have a huge file mentioned anywhere in a script and then mentioned again in another (or in the same script) you don't need to worry about it bumping up the size of your finished file with duplicated data - this is taken care of, and each referenced file will be added only once. Files which are not referenced will, of course, not be added at all.

It is also worth noting that storing a file handle does not open the file. The line...

var myHandle = 'bigImageFile.tga';

...does not read the file into memory. It is only when a handle is used by a built-in function (such as addOverlay in this case) that the file is loaded.

Built-in functions which load files from file handles:

addOverlay

anim

cacheSound

loopSound

mixOverlay

playSound

playMovie

say and think

setFloor

setFont

setLightMap

setZBuffer

startMusic

Other built-in functions which use file handles:

freeSound

getSoundCache

setSoundLoopPoints

setSoundVolume

stopSound

Curiously, these functions don't use file handles:

deleteFile

fileExists

getMatchingFiles

launch and launchWith

loadCustomData and saveCustomData

loadGame

renameFile

saveGame

showThumbnail