Calculator Community > Lua

Ti-Nspire: Changing menu items dynamically?

(1/1)

Goran:
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

Jim Bauwens:
Just re-register the menu.

For example:

--- Code: ---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

--- End code ---

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.

Goran:
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

Jim Bauwens:
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.

Navigation

[0] Message Index

Go to full version