How to make check boxes with Script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

How to make check boxes with Script

Post by DavJans » Fri Mar 25, 2016 4:42 pm

I have a new fun project but I cant get over the first bump. I have found several examples of how to create buttons using a script and a list of names for the buttons. My problem is I need to create Check boxes. I here is my last attempt that still wont work and I don't understand why :(

Code: Select all

local tButtonNames

on mouseUp
   put fld "Field 1" into tButtonNames
   send createButtons to me
end mouseUp

on createButtons
  repeat for each line tBtnName in tButtonNames
    createNamedButton tBtnName
  end repeat
end createButtons

on createNamedButton pName
   create button pName
   put the ID of btn pName into pName
   answer pName
   set the properties of btn id pName to the properties of btn "Template"
   set the name of btn id pName to tButtonNames
  put the number of btn id pName into tNum
  set the top of btn id pName to (10 + 30 * (tNum - 1))
end createNamedButton

set the properties of btn id pName to the properties of btn "Template"

This makes a check box for me if I stop there but if i jun the entire scrip it just makes a button, not a check box.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to make check boxes with Script

Post by Klaus » Fri Mar 25, 2016 5:30 pm

Hi DavJans,

set the STYLE property of your button!
...
set the style of the templatebutton to "checkbox"
create btn
...
Et voila, a checkbox :D

And use "the templatebutton" to pre-set your desired properties and then create that beast,
that is the most effective way.

And don't forget to "reset the templatebutton" when you are done, saves from surprises and
is always good style!


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: How to make check boxes with Script

Post by dunbarx » Fri Mar 25, 2016 7:14 pm

What Klaus said.

Just making sure that you know he suggested TWO methods. Setting the style of a button, which can be done at any time to any object, back and forth, same as setting any property at all,

or,

Setting the template[object], which presets ALL the properties of a newly created object. Try it. Make a button. Change its height, name, border width and backColor. Move it somewhere on the card. Now

Code: Select all

set the properties of the templateButton to the properties of button "theButtonYouJustMade"
Create a new button. Note that the new one will overlie "theButtonYouJustMade" Has to, no? After all, the rect and loc of the old button are also the properties of the new one.

Craig Newman

Post Reply