Hi @tehn and alll! I’ve got a question about creating a Params menu for my mod. I’ve looked at a few mod scripts to see how to do this, and while it looks straightforward, I can’t get the params in my mod script to generate in the global PARAMETERS menu on the Norns. I’ve got my mod running, it loads correctly, I load up a script that has its own parameters, but when I go to see the global parameters menu, I don’t see my own params listed there. I’ve added my code here. Can anyone see anything that I’m doing wrong?:
-- Mod Test for CH-Norns
-- Anthony T. Marasco (2022)
--libs and core
local mod = require "core/mods"
local UI = require("ui")
local textentry = require("textentry")
local pages
local tabs
local tab_titles = {{"Connect", "Clients"},{"Send","Receive"},{"Rooms","Chat"}}
local key_shift = false
connection_menu = {"Change Username", "Change Room", "Connect"}
client_list = {"ed","charles_12", "simon"}
menu_lists = {}
current_menu = nil
menu_selection = nil
-- Params
params:add_separator("Sending")
params:add_group("Global Options", 2)
params:add_binary("global_send_room_toggle", "send all to room (K3)","toggle", 0)
params:set_action("global_send_room_toggle",function(x)
if x == 0 then
params:hide("global_send_room_name")
elseif x == 1 then
params:show("global_send_room_name")
end
_menu.rebuild_params()
end)
params:add{
type = "option",
id = "global_send_room_name",
name = "global room",
options = {"MaxRoom","WebRoom","PDRoom"},
default = 1
}
params:hide("global_send_room_name")
mod.hook.register("system_post_startup", "my startup hacks", function()
state.system_post_startup = true
end)
mod.hook.register("script_pre_init", "my init hacks", function()
-- tweak global environment here ahead of the script `init()` function being called
end)
local state = {
isConnected = false
}
--
-- [optional] menu: extending the menu system is done by creating a table with
-- all the required menu functions defined.
--
function update_pages()
tabs:set_index(1)
tabs.titles = tab_titles[pages.index]
end
local m = {}
m.key = function(n, z)
if z == 1 then
if n == 1 then
key_shift = true
-- print("holding k1")
elseif n == 2 then
mod.menu.exit()
elseif n == 3 then
print("Selected: "..current_menu.entries[current_menu.index])
end
else
if n == 1 then
key_shift = false
-- print("k1 released")
end
end
end
-- Enc
m.enc = function(n, d)
if n == 1 and key_shift then
tabs:set_index_delta(d, false)
if tabs.index == 1 then
print("Tab 1")
else
print("Tab 2")
end
elseif n == 2 then
if pages.index == 1 then
if tabs.index == 1 then
menu_lists[1]:set_index_delta(d, false)
else
menu_lists[2]:set_index_delta(d, false)
end
end
elseif n == 3 then
-- Scroll through pages
pages:set_index_delta(d,false)
update_pages()
end
--if pages.index == 1 then
--if tabs.index == 1 then
-- Do Connect Stuff
-- if n ==2 then
--
--elseif n == 3 then
--
-- end
--else
-- Do Client Stuff
-- if n ==2 then
--
-- elseif n == 3 then
--
-- end
--end
--elseif pages.index == 2 then
--if tabs.index == 1 then
-- Do Send Stuff
-- if n ==2 then
--
-- elseif n == 3 then
--
-- end
-- else
-- Do Receive Stuff
-- if n ==2 then
--
-- elseif n == 3 then
--
-- end
-- end
-- elseif pages.index == 3 then
--if tabs.index == 1 then
-- Do Rooms Stuff
-- if n ==2 then
--
-- elseif n == 3 then
--
-- end
--else
-- Do Chat Stuff
-- if n ==2 then
--
-- elseif n == 3 then
--
-- end
--end
--end
mod.menu.redraw()
end
m.redraw = function()
screen.clear()
pages:redraw()
tabs:redraw()
if pages.index == 1 then
if tabs.index == 1 then
current_menu = menu_lists[1]
--current_menu:redraw()
else
current_menu = menu_lists[2]
--menu_lists[2]:redraw()
end
current_menu:redraw()
end
-- Page displays
screen.update()
end
-- on menu entry, ie, if you wanted to start timers
m.init = function()
-- User Interface
-- Init Pages
pages = UI.Pages.new(1,3)
tabs = UI.Tabs.new(1, tab_titles[pages.index])
menu_lists[1] = UI.List.new(0, 20,1,connection_menu)
menu_lists[2] = UI.List.new(0, 20,1, client_list)
end
m.deinit = function() end -- on menu exit
-- register the mod menu
--
-- NOTE: `mod.this_name` is a convienence variable which will be set to the name
-- of the mod which is being loaded. in order for the menu to work it must be
-- registered with a name which matches the name of the mod in the dust folder.
--
mod.menu.register(mod.this_name, m)
-- [optional] returning a value from the module allows the mod to provide
-- library functionality to scripts via the normal lua `require` function.
--
-- NOTE: it is important for scripts to use `require` to load mod functionality
-- instead of the norns specific `include` function. using `require` ensures
-- that only one copy of the mod is loaded. if a script were to use `include`
-- new copies of the menu, hook functions, and state would be loaded replacing
-- the previous registered functions/menu each time a script was run.
--
-- here we provide a single function which allows a script to get the mod's
-- state table. using this in a script would look like:
--
-- local mod = require 'name_of_mod/lib/mod'
-- local the_state = mod.get_state()
--
local api = {}
api.get_state = function()
return state
end
return api