Home‎ > ‎

Basic LiveCode Vocabulary

Basic LiveCode Vocabulary

The following LiveCode language vocabulary is only a small portion of the scripting language. However, even this small vocabulary can get you a long way. You can look these up in the LiveCode Dictionary and see examples of the commands and how they work (On the top EditBar in LiveCode is an icon titled “Dictionary”. Click on it).


Commands

    ask <text string>          pops up a dialog box with a text field to type an answer in
        e.g.     ask “What is your name”

    answer <text string>   [ with <button1> or <button2> or … or <button7> ]         pops up a dialog box with buttons
        e.g.     answer “Are you a friend”    
         or       answer “Do you want to play?” with “Yes” or “No”

    hide <object>             makes an object not visible  (it is a shortcut for "set the visible of <object> to false")
        e.g.     hide image “rock”

    show <object>          makes an object visible  (it is a shortcut for "set the visible of <object> to true")
        e.g.     show image “rock”

    disable <object>
        e.g.     disable button “bomb”

    enable <object>
        e.g.     enable button “bomb”

    put <text string> into <variable> | <field> <name>          puts data into fields or variables
        e.g.     put it into myName   
        or       put 0 into field “Score”  
        or       put “Good Job” into field “answer”

    add <number> to <variable> | <field> <name>
        e.g.     add 1 to enemiesKilled  
        or        add 10 to field “score”  

    subtract <number> from <variable> | field <name>
        e.g.     subtract 1 from numDiamonds  
        or        subtract 10 from field score    

    grab <object>        grabs an object for drag-and-drop actions
        e.g.     grab button “flower”
        or       
grab me

    move <object> [from <x,y coordinate>] to <x,y coordinate> in <time duration>]
        e.g.     move button “box” to 150,150  
         or       move image “bird” from 50,50 to 100,100 in 3 secs 

    set <property> of <object> to <value>        changes a property using code instead of the Inspector
        e.g.     set visible of button “box” to true
         or      set the loc of button box to 50,50
         or      
set color of card “level 1” to red

    wait <time duration>    where time can be secs, seconds, millisecs, and ticks
        e.g.     wait 5 secs
           or     wait 20 millisecs

    go to card “name_of_card”   
        e.g.     go to card “Level 2”

    intersect ( <object1> , <object2>  [, “pixels” | “opaque pixels” | 255 ]  )      check if 2 objects touch each other
        e.g.     Intersect (button “box”, button “E1”)  
         or       Intersect (button “box”, button “E1”, “opaque pixels”)

    send <message> to me [in <time duration>]      allows messages to be sent, good for repeating actions or doing something else
        e.g.     send "moveEnemy" to me
                   send "mouseUp" to me in 2 secs

    play “sound file” [looping]
       e.g.     play “cheering.wav”  
         or      play “JingleBells.wav” looping

    random(<number>)     generates a random number between 1 and the <number>
       e.g.    random (100)   -   (will give you a number between 1 and 100)

where:
        “|” means “or”     (do one of them)
        “[  ]” means it is optional     
                e.g.
answer “Go?”  can be answer “Go?” with “Yes” or “No” 
        <object> consists of a <type> and its <name>
                e.g. button “box”   or    graphic “curve”   or   image “shoe”    or    field “score”
        <time duration> can be “ticks” or  “millisecs/milliseconds” or “secs/seconds” or ticks 


Messages (a few examples)

         mouse messages: mouseDown, mouseUp, mouseOver, mouseEnter, mouseLeave,...
        openCard, closeCard, InitCard
        (or any name that you make up - like moveEnemy, startGame, detectCollisions, etc)


Objects:

    Objects are identified with a type and a name: e.g. button “box”, image “Spider.jpg”,  group "stars" , graphic "witch"

    Some Object Types:  images, graphics, buttons, groups, fields, cards, stack 

    Objects have properties - which can be changed manually in the “Properties Inspector” or in code using the set”  command.
                                  (e.g. set the visible of button “box” to false, set the backcolor of the card “level 1” to red)
               some properties include. loc or location  <x,y coordinates>, width, length, top, bottom, visible, backcolor, visible 


Variables - are containers for holding information or data. You use them to save information or data

     Create a variable by declaring it as local, global or just putting something into it:    
                e.g.  
                      put "Hello World." into myMessage
 
           put 100 into the Score
         

            local highScore
            global myMessage     

    


Comments - these are for people, computers ignore them

       Comments are added with either “//” or “--” at the beginning of the line
            e.g. 

                    // This is a comment - do not try to execute this line
          -- This is a comment too


Message handlers - begin with “on” 

            on <message>
                    <statements>
            end <message>

         e.g. 

                  on mouseUp
           (code goes here)
        end mouseUp


if statement  where <condition> will be True or False

            if <condition> then
                <statements>
            end if

            e.g.  

          if it is “Yes” then
            go to card “Level 2”
        end if         


            if <condition> then
                    <statements>
            else
                    <statements>
            end if 

            e.g.

              if it is “Yes” then
                  go to card “Level 2”
             else         
                  startGame
             end if         


Repeat loops

           repeat <number> times
                    <statements>
            end repeat

            e.g.  

             Repeat 3 times                            // this flashes a bomb on and off
             hide button “bomb”
             wait 20 millisecs
             show button “bomb”
             wait 20 millisecs
         end repeat

Comments