Generally speaking, all lua code that can be in luna.lua can also be in a library, and code from libraries can be exposed so that luna.lua can access it. For your per-section thing I recommend using a table.
For reference, a table like this (in a file called hud.lua)
Code: Select all
local hud = {}
hud.sections = {
[0] = "First Section",
"Second Section",
"Third Section",
[20] = "Last Section
}
return hud
maps a number to a string. Pay attention to the lefthandside of the = in the table. If you don't do them, the table entries are in-order starting at 1, so if you want gaps or want Section 0 to be recognized you have to make it explicit.
Anyway... now you can do something like this (above the return):
Code: Select all
function hud.onInitAPI()
registerEvent(hud, "onDraw")
end
function hud.onDraw()
Text.print((hud.sections[player.section] or ""), 0, 0)
end
The onInitAPI is just to make it so that onDraw can run in this library. And then in the onDraw, we substitute the 0 and 20 from before with whatever value the player's current section (0-20) is. So for Section 1 it says "Second Section", and in Section 15 it would print nothing, because of the "or" thing I put. What that does is catch if the lefthandside is not defined and then use the right side instead.
Now that's nice but there's one last step. I intentionally made the variable hud.sections instead of "local sections", so that it's part of the "hud" library table. The libary table is what's returned by require. So what you can do, in ANY luna.lua:
Code: Select all
local hud = require("hud")
hud.sections = {
[0] = "The Beginning..."
}
This will OVERWRITE the assignment from the first code block in this post, allowing you to customize the values for each section on a per-level basis, by just putting different values for this into each luna.lua.
For more info on making libraries:
https://wohlsoft.ru/wiki/index.php?titl ... ua_library
Hope this helps!