LEARNING LIVECODE #2 – Changing the state of buttons and Icons through script

1) Import your icons from your desktop by clicking on File >> Import As Control. Drag a button to your project.

Here I have two icons. The button will display an earth. Then once is is activated it will display a light bulb.

Icons and Button

2) Right click on your button and click Property Inspector.
Click on the top drop down box with ‘Basic Properties’. Click on Icons & Border like in the photo below.

Screen Shot 2013-12-12 at 11.33.04 am

3) Click on the wand to the right of the Icon box. Select your Icon. I will select the world.

Screen Shot 2013-12-12 at 11.37.08 am

4) Repeat as above and select your “on” state button for the hilite icon. I will choose the lightbulb.

5) Back on the basic properties. Unselect ‘Show Name’

Now for the coding!

6) Right click on the button and click ‘Edit Script’. Replace the script with something similar to this adding your own variable names.

local tVariable

on mouseUp

if tVariable = 0 then

set the hilite of me to true

put “1” into tVariable

else

set the hilite of me to false

put “0” into tVariable

end if

end mouseUp

And that’s it. There is probably an easier way to do this and I welcome your suggestions to update my blog to make it simple and easy.

Advertisements

Learning Livecode #1 – Loading an option menu with items.

Small simple tutorials for all the little problems you have while trying to learn a programming language.

Hopefully by the end of my trials with Livecode I will have made many small tutorials to help answer all those little questions that you have to sift through endless forum posts to obtain.

Option Menu highlighted with red square

Option Menu

This little fella is the Option Menu as highlighted above.

Click and drag the option menu over to your mainstack or card. There is multiple ways to add menu options to this button.

Manual Way 

Double click the ‘Option Menu’ (while in edit mode) and this will bring up the Property inspector.

Or right click on the object and select Property Inspector.

Property Inspector Highlighting the Menu Items

Simply type away and insert whatever menu items you require.

Code/Script Way

This is where it get’s a little tricky for a beginner but have no fear. A couple of lines of code and it’s all good.

set the text of button “your button’s name” to “Option 1” & return & “Option 2”  & return & “Option 3″…etc.

Just replace “”your button’s name” with the name of your button and “Option 1” etc with your menu options.