Home‎ > ‎Disappearing Objects‎ > ‎

Changing Properties in Code

Changing Properties  (Set, Hide, Show commands)
We have seen how objects have properties which describe them. We have looked and set them in the Property inspector. But we can also change them in our code, dynamically while the program is running.

1. Using the Property Inspector - changing a property manually, on screen 
We have seen how you can change names, colors, locations and many other properties using the "Property Inspector

The many Properties of a button

                                    
  
  

Any property that you see in the property Inspector can be changed in code too. You also can create your own custom properties to add to an object.


2. The Set Command - changing properties in code.

The set command allows you to change any property of an object in code and while your program is running. This is very powerful because you can do anything "live" and change them instantaneously.

 It has the form:

    set the <property> of <object>  to <value>

where
    <property> can be any property:    (size, color, visible, etc)
   
<object> can be any object type and name:      (button "box", graphic "Square", image "spider", etc)
    <value> depends on the property:   (size=10/12/14, color=red/blue.. visible=true/false, ...) 
            (checkboxes are either "true" or "false")

for example:

    Make it invisible                                     // checkboxes are either checked (true) or unchecked (false)
        set the visible of image "diamond" to "false"       -  (this hides it - "unchecks" it)


    Make it suddenly appear                     // checkboxes are either checked (true) or unchecked (false)
        set the visible of button "box" to "true"               -  (this shows it - "checks" it)


    Make something move
        set the location of button "box" to  200,150
        set the loc of button "box" to  200,150            // you can abbreviate location


    Change the button to a Red color with Yellow letters
        set the backcolor of the button "box" to "Red"     - (this makes the button red)

        set the textcolor of the field "choices" to "Yellow"    -  (this makes the text yellow)


     Change the card background to a green color 
        set the backcolor of the card "card 1" to "green"     


     Make the card flash on and off (blink)
        set the backcolor of the card "card 1" to "yellow"     
        wait 20 millisecs     
        set the backcolor of the card "card 1" to "green"     
        wait 20 millisecs     
        set the backcolor of the card "card 1" to "yellow"     

      Change the label of the card 
        set the label of the card "card 1" to "STOP"     

      Make the button twice as big 
        set the length of btn "box" to (the length of btn "box" * 2)     
        set the width of btn "box" to (the width of btn "box" * 2)     

      Change the frog to a princess (if the image "frog" is ID 1011 and the princess.jpg is 1021) 
        set the icon of btn "box" to 1021     
      Change it back to a frog (if the image "frog" is ID 1011 and the princess.jpg is 1021) 
         set the icon of btn "box" to 1011    
  
  

2. Alternate Commands: ("Hide" and "Show")

    Hide Command - make it invisible
        hide image "diamond"         (this hides it)

    Show Command - make it suddenly appear
        show button "box"                (this shows it)


 
NEXT:  Collecting Objects
Comments