Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: Goran on July 22, 2013, 08:40:07 am

Title: Ti-Nspire: Changing menu items dynamically?
Post 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
Title: Re: Ti-Nspire: Changing menu items dynamically?
Post by: Jim Bauwens on July 22, 2013, 10:06:18 am
Just re-register the menu.

For example:
Code: [Select]
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.
Title: Re: Ti-Nspire: Changing menu items dynamically?
Post by: Goran on July 22, 2013, 01:49:21 pm
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
Title: Re: Ti-Nspire: Changing menu items dynamically?
Post by: Jim Bauwens on July 22, 2013, 03:20:04 pm
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.