A room (sometimes referred to as a zone) is a LUA script, that is responsible for spawning segments and setting parameters (music, fog color, speed, etc.). The room files are then referenced by the level files to be put in their respective checkpoints.
There are two main functions that a room (and other LUA scripts) needs. They are init() and tick().
The init() function runs only once, when the room is loaded. Everything that is needed to setup a simple room goes here. The tick() function runs every frame. This function is usually empty and used rarely. It doesn't need anything in it. This function is mostly useful if you want it change gravity or fog color while already being the room.
This is what a room file would look like with only the functions in place, and without any parameters:
function init()
-- Most things go here
end
function tick()
-- This function runs every frame, so ~60 times a second
end
A room is customizable with many different parameters. This is a list of the most commonly used functions in rooms, with an explanation of what they do.
function init() - Runs only once, when the room is loaded.
Functions getting the parameters from the level file, for example:
pStart = mgGetBool("start", true), pEnd = mgGetBool("end", true) - Used for getting the start & end booleans.
pEndless = mgGetInt("endless", 0) - Used for getting the endless integer.
Functions commonly used for defining the properties of the room, such as:
mgFogColor(bottomR, bottomG, bottomB, topR, topG, topB) - Sets the fog color in Unit RGB format.
mgMusic("music") - Sets the music. The music argument should be the music name without .ogg.mp3, for example "19".
mgEcho(volume, delay, feedback, lowpass) - Sets the echo effect. volume controls the volume of the effect, delay controls the delay of feedbacks, feedback controls the feedback volume, and lowpass controls the strength of the low-pass filter applied to every feedback .
mgReverb(volume, reverb, lowpass) - Sets the reverb effect. volume controls the volume of the effect, reverb controls the reverb time and lowpass controls the strength of the low-pass filter applied to the effect.
mgLowPass(strength) - Sets the low-pass effect.
mgGravity(gravity) - Sets the room gravity.
mgSetRotation(rots, range) - Sets the rotation for the room. rots sets the number of rotations during the room, and range sets the range of the rotation in radians.
mgParticles(particles) - Sets the particles for the room. The argument can be set to one of these: starfield, lowrising, lowrising2, lowrising3, sides, sidesriding, falling, fallinglite, bubbles, dustyfalling.
Segments:
confSegment("seg_name", prob, times) - Defines normal segments. seg_name is the name of the segment, prob controls how often it spawns, and times can control how many times it should spawn (for example, only once in a room).
if pStart then l = l + mgSegment("seg_name", -l) end - Spawns the starting segment of the name specified with seg_name, if pStart is true.
local targetLen = 200 - Variable controlling the length of the room, i.e. it's responsible for the speed of the room.
if mgGet("player.mode")=="0" then targetLen = 150 end - Sets the length for training mode.
if mgGet("player.mode")=="2" then targetLen = 240 end - Sets the length for mayhem mode.
while l < targetLen do s = nextSegment() l = l + mgSegment(s, -l) end - Spawns the segments.
if pEnd then l = l + mgSegment("seg_name", -l) end - Spawns the starting segment of the name specified with seg_name, if pEnd is true.
mgLength(l) - Finally sets the room length.
function tick() - Runs every frame; usually an empty function, but is present in every script, as every script requires init() and tick() functions.
Boss rooms
Ticking rooms