Other Objects Besides Buttons

Other objects - radio buttons, checkboxes, drop down menus, etc

LiveCode Controls (Objects) and Their Properties

    1. Buttons - for performing actions
           A. Push Buttons - to perform an action
             Properties:

                  Styles = Push, Square, Rounded Rectangle, Transparent, Opaque and Shadow - to perform an action
                  Hilite = the property that it has been pressed and is true/false
                    if the hilite of button "Go" then             
                           (it has been pressed)
                    end if

                  Use: Usually, you have script on the button to detect when it has been pushed i.e. on mouseUp.
                      on mouseUp
                        (it has been pressed)
                      end mouseUp

                  But if you have many buttons on a card, you can use the "hilite" property in another handler

                       on mouseUp
                            if the hilite of button "Go" then
                                    (it has been pressed)
                            end if
                            if the hilite of button "Go2" then
                                    (it has been pressed)
                            end if
                            ...
                       end mouseUp

               note: This is good because all your code and ligic is in one place (on the card) and not scattered across many buttons

          C - Radio Buttons - for making 1 choice of many

              Properties:
                    Styles = Radio button and Check Box - to make choices (the radio buttons are usually used in groups)

                   But if you have many buttons on a card, you can use the "hilite" property in another handler

                       on mouseUp
                            if the hilite of button "Go" then
                                    (it has been pressed)
                            end if
                            if the hilite of button "Go2" then
                                    (it has been pressed)
                            end if
                            ...
                       end mouseUp

            D - Checkbox Buttons - for checking on/off (true or false)

              Properties:
                   Styles = Radio button and Check Box - to make choices (the radio buttons are usually used in groups)

                 But if you have many buttons on a card, you can use the "hilite" property in another handler

                       on mouseUp
                            if the hilite of button "Go" then
                                    (it has been pressed)
                            end if
                            if the hilite of button "Go2" then
                                    (it has been pressed)
                            end if
                            ...
                       end mouseUp


            E - Menu Buttons - for selecting one of many choices
               Properties:
                   Styles = menu
                   Types = option menu, pull Down menu, pop Up menu, Combo Box
                   menuMode = also the kind of menu
                   Text = the choices available
                   Label = currently chosen menu item
                   menuHistory = the line number of the chosen item     

                Use: getting the choice
                        on menuPick x
                            put x into theChoice
                        end menuPick

        2. Fields - to display or enter text 

                 Name = Field, Label Field, Scrolling, Scrolling List, Table text, list, table fields)
                            Table field - each column separated with a tab, each row by return
                            Scrolling List Fields - getting the choice , each choice is on a separate line 

                Use:
                        on mouseUp
                            put the selected text of me into theChoice
                        end mouseUp

        Data Grids - for displaying data in obth grid and form view as well as custom layouts with other LiveCode objects. Best for large data sets.


4. LiveCode Shortcuts - the "ID", the "short name" , the "name" and the "long name"

LiveCode has ways to identify objects: The "ID", the  "short name", and the "long name"

    1. ID - The ID is the number of that object. ID's are always assigned by LiveCode and are always unique. No 2 objects will have the same ID. (You use this when you skin buttons - you use the ID for the icon. 

        e.g.    1004

    2. short name - The "short name" is the name of the object. 

        e.g.   "box" or "enemy" 
        or     "square"

    3. name or abbrev name - The "name" or abbreviated name is the type and name of the object. 

        e.g.   button "box" 
        or     image "enemy" 
        or     graphic "square"

    4. long name - The long name is the complete description (or location) of the object (the card and stack that it is in)

        e.g.   button "box" of card "myCard" of stack "My Stack"   
         or     button "B" of card id 1375 of stack "/Users/admin/Downloads/school app.livecode" 


    For You To Try

    1. Make a new card, put a button on it and call the button "box. Then add the following code to the button:

            on mouseUp
                    answer the id of me
                    answer the short name of me
                    answer the long name of me
            end mouseUp

        When you click on it, you will see (in order)

                1004        (or whatever the ID # is of that object)
                Box         (the "short" name of this object)
                button "Box" of card "card id 1002 of stack "untitled"   

        In the long name, notice every object has a "type" and a "name" - button "box",  card "card id 1002", stack "untitled")

    2. Delete that code on the button and add the following code to the CARD script:

                on mouseUp
                        answer "The ID: is" && the id of the target
                        answer "Short Name: && the short name of the target
                        answer "Long Name:" && the long name of target
                end mouseUp

       now drag any objects from the "Tools Palette" to your card and click on them one by one. You will see what each is.

        You can refer to the object using any of them:

                hide button ID theID
                hide button "theShortName"
                hide button "theLongName"


5. When would we use this? - answer: when you have a large number of buttons, etc

Good question. Let's say you were making something with many buttons - a calculator, a keyboard, a memory game or anything else with many buttons. It would be tedious putting the same code on every button or object. Then if you would make a change, you would have to edit each one at a time.

Wouldn't it be easier just putting 1 copy of the code on the card script and have it see which button was pressed? 

Yes, for instance a calculator. You would have 10 buttons for the numbers (0 to 9) and normally would put code on each one. 

    On button "B1" - the button with the "1" on it

       on mouseUp
                put "1" into field "number"
       end mouseUp

    On button "B2" - the button with the "2" on it

       on mouseUp
                put "2" into field "number"
       end mouseUp 

(note: we used "B1" for the name and "1" for the label. It is not a good idea to name any object with just a number. LiveCode does not know id you mean the ID or the name of the object. So instead we include a "B" before each number - as the name)

Instead, you can just do one script on the card 

    on the CARD Script

        on mouseUp
                put char 2 of the short name of the target into the field "number"
        end mouseUp

A little more complicated (not really if you understand it) but a lot less work. You are done. You do not have to do any more scripts

        

        ...more to come

Comments