#Introduction
In this tutorial, you make a mod that hides the game's HUD: the star, coin and life counters and the life meter. The mod adds an option to the Mods page, so players can show the HUD again without restarting the game.
You learn how to:
- Add an option to a mod and read it from code.
- Run code every frame with
on frame. - Stop one of the game's functions with a
hook beforeandskip. - React when the player changes an option with
on option.
#Prerequisites
- Nebula, installed with Nebula Setup.
- LumaLink. For more information, see Installing LumaLink.
- We recommend that you complete the Quickstart for Nebula mods first.
#Creating the mod
Create the mod folder, and add an option named hide.
lumalink new hide-the-hud --id hide-the-hud --name "Hide the HUD" --summary "Takes the counters and the life meter off the screen." --author YOUR-NAME
lumalink add option hide hide-the-hud --kind toggle --default true --name "Hide the HUD"lumalink add option adds a toggle named Hide the HUD to the mod's entry on the Mods page. It is on by default.
#Writing the code
Create hide-the-hud/source/main.lum with this code:
option hide: bool
// The game shows the HUD when a level starts. Put it away on the first frame it is up.
on frame {
if hide and MR::isExistSceneObj(SceneObj_GameSceneLayoutHolder as i32) and MR::isActiveDefaultGameLayout() {
MR::deactivateDefaultGameLayout()
}
}
// The game brings the HUD back after each cutscene through this function.
hook before GameSceneLayoutHolder::activateDefaultGameLayout() {
if hide {
skip
}
}
// The option turned off during play: the HUD comes back at once.
on option hide {
if not hide and MR::isExistSceneObj(SceneObj_GameSceneLayoutHolder as i32) and not MR::isDemoActive() {
MR::activateDefaultGameLayout()
}
}option hide: booldeclares the option. Your code reads it like a variable.on frameruns every frame. When a level is loaded (the HUD's holder exists) and the HUD is showing, it calls the game's ownMR::deactivateDefaultGameLayout, which hides every counter and the meter.hook before GameSceneLayoutHolder::activateDefaultGameLayout()runs before the game shows the HUD again, for example after a cutscene.skipstops the game's call.on option hideruns when the player changes the option. When the player turns it off outside a cutscene, the HUD appears again immediately.
#Building and checking the mod
lumalink build hide-the-hud
lumalink check hide-the-hudThe last line of the check output is Errors: 0.
#Testing the mod
The finished mod includes two tests:
tests/hiddenenters Good Egg Galaxy, callsMR::isActiveDefaultGameLayout, and takes a picture. The test passes when the function returnsfalseand the corners where the life meter and the coin counter would be show the sky.tests/showndoes the same with the option turned off. The test passes when the HUD is showing and the life meter is drawn.
To run the tests, copy the tests folder from the finished mod into hide-the-hud, then run:
lumalink test hide-the-hudNote
In the current version, the test harness cannot start a mod with an option set, so tests/shown ends with harness-error.
#Playing the mod
Pack the mod.
Shell lumalink pack hide-the-hudDrag the
.lumafile onto the game's window, and turn the mod on in the Mods page.Enter a level. The HUD is hidden. To show it again, turn off Hide the HUD on the Mods page. You do not need to restart the game.