Jump to content

CReating Toggle buttons based on a dynamic list


Verliezer

Recommended Posts

Hi,

 

Hope anybody can help me.

In the LUA examples from NQ in using Toggle Buttons on a screen, the creation of the Toggle Buttons is hard coded (fixed). Like this
 

exampleA = Toggle(rx / 7 * 4, ry / 5 - rx / 40, rx / 20, rx / 20, false, "Example Toggle A (Linked)", font)

exampleA:draw(exampleLayer)

 

This works very wel. However I would like it to be a bit more flexible for script re-use purposes. I would like to create the Toggle Buttons based on aKindOfList. For each item in that list a Toggle Button should get created. I created something like this:

if not init then
    init = true
    listofbuttons = {}
    For  i, id in pairs (aKindOfToggleButtonList) do
           listofbuttons[#listofbuttons + 1] = Toggle(rx / 7 * 4, ry / 5 - rx / 40, rx / 20, rx / 20, false, "Example Toggle A (Linked)", font)
    end
end

For i, button in pairs(listofbuttons) do
      button:draw(exampleLayer)
end

 

This does not work. It doesn't give any error messages at all. From a coding perspective there seems nothing wrong. This made me wonder if it is possible at all to initiate objects and store them in a Array?

 

Good to mention that I validated the for looping if it actually is going into the loop, it all works fine. It just does not seems to store the Toggle object created into the array.

 

Is there anybody who can help (maybe NQ_LIGO)?

 

ps NQ_ligo created the example on github: 

  1. 03 - Lua Screen Widgets Objects
  2. render_toggle.lua
Edited by Verliezer
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...