Lua Radio buttons

Forum: Programming and Scripting
Topic: Lua Radio buttons
started by: u2musicmike

Posted by u2musicmike on Jan. 24 2007,20:34
I am trying to get radio buttons to work in a short lua program:

Code Sample

selbc = fltk:Fl_Round_Button(130,20,18,25,"Breads_Cereals")
-- selbc:value(1)

selmd = fltk:Fl_Round_Button(260,20,18,25,"Main Dishes")

selveg = fltk:Fl_Round_Button(130,40,18,25,"Vegetables")

selmisc = fltk:Fl_Round_Button(260,40,18,25,"Miscellaneous")

-- setonly():void

if selmisc:value() == 1 then
foodcat = "Miscellaneous"
elseif selmd:value() == 1 then
foodcat = "Main Dishes"
elseif selveg:value() == 1 then
foodcat = "Vegetables"
elseif selbc:value() == 1 then
foodcat = "Breads_Cereals"

No matter what I click the value is never set unless I do it manually.  I tried to do it like the fdtool program but I am missing something.  Can somebody point me to a site that has some lua radio button code?

Posted by roberts on Jan. 24 2007,21:11
What is your enclosing container, group or window?
What gui is going to have the callback attached so you can display the results of the radio button selection.

We have 5 lua programs that use radio buttons, from simple to more complex for you to study.


Posted by mikshaw on Jan. 24 2007,22:22
Something like this might help?

Code Sample

function catfood(self)

selbc = fltk:Fl_Round_Button(30,20,18,25,"Breads_Cereals")
selbc:type(fltk.FL_RADIO_BUTTON); selbc:callback(catfood);
selmd = fltk:Fl_Round_Button(160,20,18,25,"Main Dishes")
selmd:type(fltk.FL_RADIO_BUTTON); selmd:callback(catfood);
selveg = fltk:Fl_Round_Button(30,40,18,25,"Vegetables")
selveg:type(fltk.FL_RADIO_BUTTON); selveg:callback(catfood);
selmisc = fltk:Fl_Round_Button(160,40,18,25,"Miscellaneous")
selmisc:type(fltk.FL_RADIO_BUTTON); selmisc:callback(catfood);


If you have multiple sets of radio buttons you'll probably need to create a unique group for each set of buttons.  Also, this example uses the label of each button to determine the value of foodcat

Posted by u2musicmike on Jan. 26 2007,15:41
Thanks for the help.  I was really stuck.  The radio buttons work now.  That is a pretty neat trick to pull the labels from the buttons.  I don't know the lua programming language very well but I am trying to build a data entry form for a sqlite database.  As a starting point I took the window routines from the fdtool.lua program and changed a few things like button names and input fields.  If I can get it to produce the sql statement that I want I will post the code or make a dsl package.

One thing that I found strange was the function has to be before the radio button statements.

Posted by mikshaw on Jan. 26 2007,18:12
Apparently some languages don't require the function to be defined first, but  Lua seems to be one that does. I assume this is because Lua is interpreted line-by-line at runtime, so it needs to know what a callback does before it can use the callback. Maybe the function could first be declared without being fully defined, like in C, but I haven't really had any need or desire to experiment with that yet.

I know nothing about using sql databases yet, so I can't help there. So far my experience with saving and retreiving data has been in parsing plain text rc files, like many of the DSL tools do.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.