Musix.lua

From Moondust Wiki
Revision as of 17:44, 23 July 2016 by Enjl (talk | contribs) (API.load)
Jump to navigation Jump to search

Download Latest Version

Musix is a small library which allows the easy creation of music codes!

Installation

Drop the musix.lua file in the LuaScriptsLib folder.

How to use

First, load in the API. Then, you can set the music codes for every section individually. If you want, you can also customise the position of the music code for each section, and how long it will display (though this is global, it can be made to change for each section).

Once this is done, type "music" in-game to see the music code appear.

Examples

local musix = API.load("musix");
    
function onLoad()
    musix.musicCodes[0] = "The music code for the first section!"
end

This will display the text "The music code for the first section!" when the code "music" is typed.

local musix = API.load("musix");
    
function onLoad()
    musix.musicCodes[0] = "The music code for the first section!"
    musix.musicPositions[0] = { x = 0, y = 0 }
end

This will do the same as above, but the text will appear in the top left corner rather than the bottom left. By default, the position of any music code is (20, 580).

local musix = API.load("musix");

function onLoad()
    musix.musicCodes[0] = "The music code for the first section!"
    musix.musicCodes[1] = "The music code for the second section!"
    musix.musicPositions[0] = { x = 0, y = 0 }
end
    
function onLoop()
    if player.section == 1 then
        musix.counter = 100;
    else
        musix.counter = 400;
    end
end

This bit of code works as before, but with some interesting changes. Firstly, this has a music code for two different sections. The code for the first section will display in the top left of the screen, while fthe second section's music code will display at the default bottom right. However, this also changes the time the music code is displayed for. By default, music codes are displayed for 400 frames (about 6.7 seconds), but this makes the music code for the second section last for just 100 frames (about 1.7 seconds).

Documentation

Values

These are variables you can access

counter number The number of frames the music codes will display for. By default, this is 400. A guideline for using this value is that 60 frames is approximately 1 second.
musicCodes table(string) A 21 object list, containing the music codes for each section. By default, these are all empty. This is a 0-indexed table, so the music code for the first section is at musicCodes[0].
musicPositions table(Position) A 21 object list, containing the position on the screen of the top left corner of the music code for each section. By default, these are all the point (20, 580). This is a 0-indexed table, so the position for the first section is at musicPositions[0].


Structures

Position x y
number

The X coordinate of the top left of the music code on the screen.

number

The Y coordinate of the top left of the music code on the screen.

Internal Use Functions

These are functions that the library uses to function, but are not necessary for the user

onInitAPI
Registers the API events. nil
update
Updates the library each frame. nil