Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: Goran on July 22, 2013, 08:40:07 am
-
Hello,
Firstly, sorry if this question has been answered already (link please).
I want to change the menu content during lua script execution.
I found in "Lua Scripting API Reference Guide" the following sentence:
"Beginning with platform.apiLevel = '2.0', the names of the tool palette items
can be changed dynamically while the program is running."
but I am missing an example.
Any help would be appreciated.
Thanks,
Goran
-
Just re-register the menu.
For example:
function swap()
menu[1], menu[2] = menu[2], menu[1]
toolpalette.register(menu)
end
menu = {
{"Analysis",
{"Decimal", print},
{"Hexadecimal", print},
{"Octal", print},
{"Binary", print},
{"Signed", print},
{"Unsigned", print},
},
{"Boolean",
{"And", print},
{"Or", print},
{"XOr", print},
{"Not", print},
},
{"Toggle",
{"Swap menu", swap}
}
}
function on.construction()
toolpalette.register(menu)
end
When clicking on swap, the first two menus will always be swapped. Silly example, but it shows that you dynamically can change the menu items.
-
Thanks Jim,
great, that helped!
I have few other questions (different TI-Nspire/Lua topics), but I'll rather open new topics, I think it's better for the community.
Best regards,
Goran
-
Glad I could help you :)
Also, it would be indeed better to open new topics or you could also post in the Lua Q&A thread if it are small questions.