Lua Scripting
infernoSand's modification (modding, scripting, etc.) system is based around a scripting library for C/C++ called Lua. It has many things built in that would have caused inferno (the game's creator) a lot of troubles and set backs. Lua is an expansive and easy-to-use library.
infernoSand Scripting
Most of this is taken from the default mod "config.txt."
infernoSand Lua Scripting Tutorial
~~~~RULES~~~~
1.) When using element names, ALWAYS surround them with quotation marks.
2.) ALWAYS supply the correct amount of parameters (this may be fixed in later versions).
~~~~SYNTAX~~~~
resize(width, height)
If not used, will resize the screen to 500x500. Only use this once! Handling for multiple resizing is not added yet.
apptitle("Window text")
Window Text will appear before the version number of infernoSand.
include("filename")
Include a separate file
Elements:
element("name",red,green,blue,weight,slide,viscosity,deathrate,dieto)
Red, green, blue - 0-255
Weight, spray, deathrate - 0-32768
Weight can be negative.
Dieto is an integer (from 0 to 1000)
viscosity - 1 - 32768. CAN NOT BE 0.
Interactions:
interaction("this element","reacts with this","first one turns to this","second element turns to this",rate)
All elements must be declared before the interaction line (will look into fixing this).
Interactionfuncs:
interactionfunc(ELEM_id1, ELEM_id2,"functionname",rate)
Because this is meant for more advanced uses, the reacting elements should be integer values.
Functionname is the name of a function that will run when the interaction occurs.
interactx/y and reactx/x are set whenever an interactionfunc runs
(the former referring to the first element and the latter referring to the second element).
keycode("suffix",keycode)
Sets the given keycode to, in this case, the function KEY_suffix. For example,
keycode('a',97) sets keycode 97 (the A key on English language keyboards) to the function
KEY_a, KEYUP_a, and KEYHELD_ for the appropriate actions. All English language keyboards (QWERTY, at least) have keycodes preset (see keycode.lua)
print("text to print", a number, another number, etc.)
Prints each parameter, whether it be a variable of any type or a constant string of characters, to stdout.txt.
printerr() does the same thing but it prints to stderr.txt.
mousedown, mousemove, mouseup, mousewheeldown, mousewheelup, mouseheld
These are all functions set to the appropriate action.
second
A function that runs once per second.
iExit()
Safely (frees allocated memory and does app cleanup) exits infernoSand. You could also use Lua's os.exit(), but it isn't as safe.
luamem()
Returns the memory (in KB) that the Lua portion of infernoSand is currently using.
Useful variables:
speed
Max speed (not fully functional)
mx, my, button
The mouse coordinates and the button currently being pressed (1 = left, 2 = middle, 3 = right).
MENUFOCUS, MENUINPUT, ELEMCOUNT, border
The first three are if the mouse is focused on a menu, you clicked a menu, and the current element count. The fourth is the border state, and is changeable.
writetoscreen(x,y,fontsize,"text",red,green,blue)
Writes the given text at x,y in the given fontsize and rgb color.
messagebox("windowtext","boxtext",type)
Creates a popup window. The type 0 is just an "OK" screen, while type 1 creates an "OK / CANCEL" screen that returns 1 for OK and 0 for Cancel.
Drawing:
There are several drawing types.
draw(point,ELEM_id,x,y)
Draws a pixel of the given element at x,y
draw(circle,ELEM_id,x,y,radius)
Draws a circle with given radius of the given element with center at x,y
draw(filledcircle,ELEM_id,x,y,radius)
Same as circle, but draws it filled.
draw(filledrect,ELEM_id,x,y,width,height)
Draws a filledrectangle of the given element at x,y with the given width and height. Width and height being negative just means it draws in the opposite direction.
draw(line,ELEM_id,x1,y1,x2,y2)
Draws the given element from x1,y1 to x2,y2
gamerversion
A string that holds " infernoSand" and the version name. For instance, Alpha 4's gameversion holds the value " infernoSand Alpha 4".
- Working element icon script.
- MENUFOCUS, MENUINPUT, MENUHANDLE_hasinput and _hasfocus, ELEMCOUNT, working border and border variable
- writetoscreen() added
- messagebox() added
- Icons for first mod added
- 'line' draw type
- gameversion variable
Edit9:
- _CHANGELOG.txt added
Edit11:
- function.lua added
- clearscreen() scripted function added
- drawtriangle(elem, x1, y1, x2, y2, x3, y3) scripted function added
Edit12:
- Added KEYHELD_ functions
~~~ADVANCED LUA FUNCTIONS~~~
Formatting a string (adding multiple strings together):
variable = string.format("%%x asks for a number (like %x) and %%s asks for a string (like %s)",54,"this string here")
The first parameter is a string that should contain some formatting escape strings, such as %x and %s. For each of these, another parameter is asked according to its type (%x asks for a number, and %s asks for a string). Using %% lets you place a normal '%' character.
Getting the time:
os.date("*t",os.time()).type
type can be year, month, day, hour, min (0-59), sec (0-61 for some reason), wday (weekday, Sunday is 1), or isdst (Boolean values for the daylight savings time status).
Example:
print(os.date("*t",os.time()).hour,":",os.date("*t",os.time()).min,":",os.date("*t",os.time()).sec)
This prints the current time down to the second.