Functions
Aus EnigmaWiki
Verfügbare Sprachen: Deutsch, English, Русский
Here are the Lua-functions for objectmanipulation, sorted alphabetically, and explained. Some of them marked DEPRECATED , please DO NOT use them in your level! They are only here for sake of completeness, and they can still occur in older levels.
So all of the functions have unique Signature, in order to determine the Types of values.
List of functions
CreateWorld(width, height)
Signature: nil = CreateWorld(int, int)
Description:
Creates a world with width width and height height. The function has an alias:
create_world(width, height).
Example:
A One-room-level
CreateWorld(20, 13)
display.SetFollowMode(mode)
Signature: nil = display.SetFollowMode(mode)
Description:
Sets the scrollmode to another value.
Values for mode can be:
-
display.FOLLOW_NONE: No Scroll (seems not to work) -
display.FOLLOW_SCROLLING: Scrolls by a half screen. -
display.FOLLOW_SCREEN: When the actor reaches the edge of the screen, the next screen will be shown. This is the standard setting. -
display.FOLLOW_SCREENSCROLLING: When the actor reaches the edge of the screen, The camera moves towards the next screen. -
display.FOLLOW_SMOOTH: The actor is always in the middle of the screen.
Example:
Sets the scrollmode to smooth:
display.SetFollowMode(display.FOLLOW_SMOOTH)
draw_border(objectname[, x[, y[, w[, h]]]])
Signature: nil = draw_border(objectname, int, int, int, int)
Description:
Draws a border with the stone objectname. Optionally you can define the coordinates (x; y) of the upper-left corner, the width w und height h. If you do not use the optional arguments, the whole level will be framed.
Example:
draw_border("st-marble") draw_border("st-greenbrown", 0,5,3,3)
draw_checkerboard_floor(objectname1, objectname2, x, y, w, h[, attributes)
Signature: nil = draw_checkerboard_floor(objectname, objectname, int, int, int, int, attributelist)
Description:
Draws a checkerboard with the floors objectname1 and objectname2 with upper left corner x, y up to the width w and the height h.
In the upper left corner the floor has the type objectname1.
Example:
draw_checkerboard_floor("fl-abyss", "fl-rough", 2, 2, 23, 11) draw_checkerboard_floor("fl-normal", "fl-inverse", 0, 0, levelw, levelh)
draw_floor(objectname, {x, y}, {xstep, ystep}, n[, attributes])
Signature: nil = draw_floor(objectname, coordinates, table, int, attributelist)
Description:
Draws a square of tiles from the point x,y with step xstep,ystep up to the length n.
Example:
draw_floor("fl-abyss", {3,0}, {0,1}, level_height) draw_floor("fl-gradient", {15, 5}, {1,0}, 4, {type=1}) draw_floor("fl-water", {level_width-4,3}, {0,1}, level_height-6)
draw_items(objectname, {x, y}, {xstep, ystep}, n[ ,attributes])
Signature: nil = draw_floor(objectname, coordinates, table, int, attributelist)
Description:
Draws a square of items from the point x,y with step xstep,ystep up to the length n.
Example:
draw_items("it-trigger", {3,3}, {2,0}, 8) draw_items("it-tinyhill", {5,3}, {2,0}, 7)
draw_stones(objectname, {x, y}, {xstep, ystep}, n[, attributes])
Signature: nil = draw_stones(objectname, coordinates, [[table]], int, attributelist)
Description:
Draws a square of stones from the point x,y with step xstep,ystep up to the length n.
Example:
draw_stones("st-grate1", {9,1},{0,1}, 5) draw_stones("st-stone_break", {21,1}, {1,0}, 10) function draw_border(stonename, x0, y0, w, h) draw_stones(stonename, {x0,y0}, {1,0}, w) draw_stones(stonename, {x0,y0+h-1},{1,0}, w) draw_stones(stonename, {x0,y0}, {0,1}, h) draw_stones(stonename, {x0+w-1,y0},{0,1}, h) end
enigma.AddConstantForce(force_x, force_y)
Signature: nil = enigma.AddConstantForce(float, float)
Description:
Sets the global value of "gravity" with force_x, force_y for the whole level.
If the force points left(x)/upwards(y), force_x/y is negative, if right(x)/downwards(y), positive.
Example:
A level's "gravity" set to the down-left:
enigma.AddConstantForce(-10, 10)
enigma.AddRubberBand(actor, object[, strength[, length[, minlength]]])
Signature: nil = enigma.AddRubberBand(objectname, objectname, int, int, int)
Description:
Binds an actor and object with a rubberband.
Optional attributes:
- strength: Sets the strength of the rubberband, also the force needed to stretch the band (default: 10).
- length: the length of the rubberband in unstretched state (default: 2).
- minlength: minimal length of the band (default: 0).
Example:
local ac=set_actor("ac-blackball", 1.5,7.5) local st=set_stone("st-brownie", 10,6) enigma.AddRubberBand(ac, st, 50, 10)
enigma.AddScramble(x, y, d)
PROBABLY DEPRECATED
Signature: nil = enigma.AddScramble(int, int, string)
Description:
Add Scramble at Position (x; y) in direction {"n","e","s","w"}.
enigma.date("dateformatstring")
Signature: string = enigma.date(string)
Description:
Returns the current date. This function is mentioned because of completeness only, do not use it in levels.
enigma.EmitSound(soundfloor,play)
DEPRECATED
Internal system function
Description:
In good old times, it was used to play the sounds, but now DO NOT USE IT ANYMORE!!!
This function is used in Enigma V #73 - Acoustic Memory to play sounds when the marble rolls over a trigger.
enigma.GetAttrib(objectreference, attributename)
Signature: string|nil = enigma.GetAttrib(objectreference, string)
Description:
Gives the value of the attribute attributename of the object objectreference.
Example:
local bolder1 = set_stone("st-bolder", 1, 1) local bolder_dir = enigma.GetAttrib(bolder1, "direction")
enigma.GetNamedObject(name)
Signature: objectreference|nil = enigma.GetNamedObject(name)
Description:
Returns a reference to an object with the name name. Returns nil, if no adequate object exists.
Example:
set_stone("st-wood", 7, 11, {name="woodie"}) ... local wood_block = enigma.GetNamedObject("woodie")
enigma.GetFloor(x, y)
Signature: objectreference|nil = enigma.GetFloor(int, int)
Description:
Gives a reference to floor at coordinates (x; y).
Example:
set_floor("fl-black", 2, 2) local tile = enigma.GetFloor(2, 2)
enigma.GetItem(x, y)
Signature: objectreference|nil = enigma.GetItem(int, int)
Description:
Gives a reference to item at coordinates (x; y).
Example:
set_item("it-rubberband", 2, 2) local tool = enigma.GetItem(2, 2)
enigma.GetKind(objectreference)
Signature: objectname|nil = enigma.GetKind(objectreference)
Description:
Gives the kind of object objectreference.
Example:
local block = set_stone("st-block", 5, 3) local kind = enigma.GetKind(block)
kind will have the value "st-block".
enigma.GetPos(objectreference)
Signature: int, int = enigma.GetPos(objectreference)
Description:
Gives the coordinates of object named objectreference.
Attention: The position is always rounded to integers!
Example:
local block = set_stone("st-block", 5, 3) local pos_x, pos_y = enigma.GetPos(block)
With some advanced Lua programming, both values can be collected directly into a pair of coordinates (coordinates):
local block = set_stone("st-block", 5, 3) local pos = {enigma.GetPos(block)}
enigma.GetStone(x, y)
Signature: objectreference|nil = enigma.GetStone(int, int)
Description:
Gives a reference to the stone at coordinates (x; y)).
Example:
set_stone("st-actorimpulse", 3, 6) local ai = enigma.GetStone(3, 6)
enigma.isSolved(filename)
DEPRECATED
Description:
It checked, if the level filename had been solved.
DO NOT USE THIS FUNCTION IN YOUR LEVELS!
enigma.KillFloor(x, y)
Signature: nil = enigma.KillFloor(int, int)
Description:
Deletes the floor at coordinates (x; y).
Attention: This function is out of operation, IT CAUSES SEGFAULT!
Example:
fill_floor("fl-water", 10, 7, 3, 3) enigma.KillFloor(11, 8)
enigma.KillItem(x, y)
Signature: nil = enigma.KillItem(int, int)
Description:
Deletes item at coordinates (x; y).
Example:
draw_items("it-weight", {5,5}, {1,1}, 5) enigma.KillItem(7, 7)
enigma.KillStone(x, y)
Signature: nil = enigma.KillStone(int, int)
Description:
Deletes stone at coordinates (x; y).
Example:
Wall with hole:
draw_stones("st-glass", {10,1}, {0,1}, 11) enigma.KillStone(10, 6)
enigma.LoadLib(libraryId)
Description: Used to load libraries to Enigma. Further usage not cleared yet...
enigma.NameObject(objectreference, name)
Signature: nil = enigma.NameObject(objectreference, string)
Description:
Gives name name for the object objectreference.
Example:
local metal = set_stone("st-metal", 2, 2) enigma.NameObject(metal, "the_metal")
enigma.SetAttrib(objectreference, attributename, value)
Signature: nil = enigma.SetAttrib(objectreference, string, string)
Description:
Sets attribute attributename of object objectreference to value value.
Example:
An object-naming: (You should use enigma.NameObject instead)
local las = set_stone("st-laser", 1, 4, {on=FALSE, dir=NORTH}) enigma.SetAttrib(las, "name", "laser")
This example not works:
function toggle_on() enigma.SetAttrib(lightsource, "on", TRUE) end set_stone("st-switch", 1, 1, {action="callback", target="toggle_on"}) lightsource = set_stone("st-laser", 2, 2, {name="the_laser"})
enigma.SetAttribs(object, attributes)
Signature: nil = enigma.SetAttribs(objectreference|objectname, attributelist)
Description:
Sets the attributes attributes of object object. object can be either the objectreference or the named object objectname.
Attention: This function is not working yet! CAUSES SEGFAULT
Example:
local las = set_stone("st-laser", 1, 4, {on=FALSE, dir=NORTH}) enigma.SetAttribs(las, {on=TRUE, dir=WEST})
enigma.SetDefaultAttribs(objectname, attributes)
Signature: nil = enigma.SetDefaultAttribs(objectname, attributelist)
Description:
Sets the default values of object objectname, so these attributes not needed to set later.
Attention: This function is out of operation, IT CAUSES SEGFAULT!
Example:
enigma.SetDefaultAttribs("it-wormhole", {range=1.0, strength=10}) set_item("it-wormhole", 11, 6, {targetx="48.5",targety="56.5"})
enigma.SetCompatibility(compatibility)
DEPRECEATED
In formal versions this function was used to set the compatibility.
Now you can set it in the xml-metafield with: el:compatibility
DO NOT USE IT UNLESS YOU ARE MAKING A LEVEL FOR THE GOOD OLD OXYD :-)
enigma.SetScrambleIntensity(integer)
PROBABLY DEPRECATED
Signature: nil = enigma.SetScrambleIntensity(int)
Description:
Sets the intensity of the scramble to integer.
fill_floor(objectname, x, y, w, h)
Signature: nil = fill_floor(objectname, int, int, int, int)
Description:
Fills a square with upper-left corner x,y with sizes w,h with floor name.
Example:
fill_floor("fl-space", 0,0, level_width,level_height) -- these two lines fill_floor("fl-space") -- do the same fill_floor("fl-gray", 1, 1, level_width-2, level_height-2) fill_floor("fl-water", 24,47, 11,1)
fill_items(objectname, x, y, w, h)
Signature: nil = fill_items(objectname, int, int, int, int)
Description:
Fills a square with upper-left corner x,y with sizes w,h with items objectname.
Example:
fill_items("it-wormhole", 1, 1, 3, 3) -- field of 3x3 wormholes
fill_stones(objectname, x, y, w, h)
Signature: nil = fill_stones(objectname, int, int, int, int)
Description:
Fills a square with upper-left corner x,y with sizes w,h with stones objectname.
Example:
fill_stones("st-chameleon", 1, 1, 18, 11) fill_stones("st-grate1", 1, 5, 5, 7) fill_stones("st-death", 9, 5, 2, 2)
MakeObject(objectname, attributes)
Signature: objectreference = MakeObject(objectname, attributelist)
Description:
Internal System Function
Quoted from the Enigma-Reference-Manual:
"To my best knowledge, no one uses this function in their levels. You should rather use set_floor/stone/item functions for creating particular enigma objects. If you need this function, you are probably guru and you don’t need this manual either." :-)
oxyd_closeall()
Signature: nil = oxyd_closeall()
Description:
Closes all Oxyd-Stones.
Example:
set_item("it-trigger", 3, 5, {action="callback", target="oxyd_closeall"})
oxyd_shuffle()
Signature: nil = oxyd_shuffle()
Description:
Mixes the Oxyd colours randomly, so the colours will be redistributed to all stones.
Even if definite colours are in use.
Example:
set_item("it-trigger", 3, 5, {action="callback", target="oxyd_shuffle"})
SendMessage(name|objectreference, message [,data])
Signature: nil = SendMessage(name|objectreference, string, ?|nil)
Description:
Sends the message message to an object.object can be either the objectreference or the named object name.
Example:
set_item("it-hollow", 5, 10, {name="my hollow"}) SendMessage("my hollow","trigger")
In Example a hollow with name "my hollow" is created. Then the hollow "my hollow" gets the message trigger, which makes the hollow turn into a hill.
set_actor(objectame, x, y [, attributes])
Signature: objectreference = set_actor(objectname, float, float, attributelist)
Description:
Sets an actor objectame to the coordinates x,y (Marks the middle of the actor!). Optionally the actor can get the attribute attributes. An attributelist can be also used {attrib1=value, attrib2=value, ...}. The function has an alias: SetActor(objectame, x, y [, attributes]).
Example:
set_actor("ac-bug", 5, 10) set_actor("ac-blackball", 1, 1, {player=0, mouseforce=1.5})
set_floor(objectname, x, y [,attributes])
Signature: objectreference = set_floor(objectname, int, int, attributelist)
Description:
This function sets the floor objectname into the position x,y. Optionally the floor can get the attribute attributes. An attribute list can be also used {attrib1=value, attrib2=value, ...}.
Example:
set_floor("fl-tigris", 5, 10) set_floor("fl-bluegray", 1, 1, {name="blaugrau"}) function setup_gradient_rose(x,y) set_floor("fl-gradient", x, y+1, {type=1}) set_floor("fl-gradient", x, y-1, {type=2}) set_floor("fl-gradient", x+1, y, {type=3}) set_floor("fl-gradient", x-1, y, {type=4}) end
set_item(objectname, x, y[, attributes])
Signature: objectreference = set_item(objectname, int, int, attributelist)
Description:
This function sets an item objectname to the position x,y. Optionally the item can get the attribute attributes. An attribute list can be also used {attrib1=value, attrib2=value, ...}.
set_item("it-trigger", 34, 3, {action="openclose", target="bridge1"})
set_stone(objectname, x, y[, attributes])
Signature: objectreference = set_stone(objectname, int, int, attributeliste)
Description:
This function sets the stone objectname into the position x,y. Optionally the stone can get the attribute attributes. An attribute list can be also used {attrib1=value, attrib2=value, ...}.
Example:
set_stone("st-yellow", 5, 10) set_stone("st-glass", 1, 1, {name="glasstein"}) set_stone("st-door", 18, 6, {name="door01", type="h"}) set_stone("st-bolder", 2, 11, {name="bolder01", direction=NORTH})
set_stones(objectname, positionlist[, attributes])
Signature: nil = set_stones(objectname, table with coordinates, attributelist)
Description:
positionlist is a complex list including x and y coordinates. This method is suitable for setting large number of equal stones into intended places. Optionally the stone can get the attribute attributes. An attribute list can be also used {attrib1=value, attrib2=value, ...}.
Example:
set_stones("st-glass", {{1,6},{1,12},{34,1},{34,2},{35,2},{36,1},{36,2}}) set_stones(bordertile, {{34, 1}, {34, 5}, {34, 7}, {34, 11}}) ... set_stones("st-invisible", {{7,9}}) -- these two lines set_stone("st-invisible", 7, 9) -- do the same

