create buttons from a script

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quinntk
Posts: 4
Joined: Fri Nov 30, 2007 8:02 am

create buttons from a script

Post by quinntk » Fri Nov 30, 2007 5:47 pm

Hi guys,

i just have a few questions that I would love some help with.

I'm I need to create a button on a card by using a script.

I'm currently using "create button "Button1" and that puts the button directly in the middle of the card.

However, I need the button to be a radio button not a push button? How can I do this? In addition, is there anyway to format the font of button?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Post by FourthWorld » Fri Nov 30, 2007 6:31 pm

There are at least two ways to do this. I'll cover both briefly here:

1. Modify after creation
You can lock the screen, create the button, set its style and location properties, and then unlock the screen to have the control appear how you want it.

2. Modify before creation
For each of its object types Rev maintains a template object ("the templateButton", "the templateStack", etc.). These objects are used whenever a new object of that type is created. So if you set the style of the templatebutton to "radioButton", and set its location to the desired loc, when you use the "create button" command the control will appear as you want it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

quinntk
Posts: 4
Joined: Fri Nov 30, 2007 8:02 am

Post by quinntk » Sun Dec 02, 2007 9:33 pm

okay that worked for the customizing...but now i have another issue

I'm reading a word from a file and I need that word to be the name of the button I'm trying to create.

This is the script I'm using (i've already got the file I'm using opened above so thats not the problem)

Code: Select all

on opencard
  repeat for NumberofButtons times
     read from file "PollQuestions.txt" for 1 line
     create button it
   end repeat
end opencard
my first line of the file says "Yes", my second line says "No"

while this script is giving me two buttons, its naming and labeling the buttons "Yes_" and "No_". I need the buttons to say the words without the underscore.

I've put the "it" into something else and had it display and when I do that, i get "Yes" and "No" without the underscore so I think its something dealing with the creation of the button

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Mon Dec 03, 2007 1:05 am

most likely the underscore is due to line endings, or encoding issues. Try to open the file in text or binary form. If the text file was created on another Platform, Rev might be confused when in Text mode, and you need to do a replace of the line endings (see also the entry of the "return" constant).

Alternatively, use the "put URL" form instead of the "read until" form, although that will load the file at once, it'll allows you to access it much easier. Your example task would look like this with "put URL":

Code: Select all

on opencard 
  put url ("file:" & "PollQuestions.txt") into theFile
  repeat for each line theLine in theFile 
     create button theLine
   end repeat 
end opencard
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply

Return to “Talking LiveCode”