Use the icon of button as a conditional statement (if else)?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Cheong
Posts: 30
Joined: Tue Oct 27, 2015 7:49 am

Use the icon of button as a conditional statement (if else)?

Post by Cheong » Thu Nov 05, 2015 3:36 am

Dear Readers,

Is it possible to use the icon as conditional statement for if then else?

Example that I tried:

Code: Select all

if the icon of button "ButtonTest" is "TurnOn" then
  set the icon of button "ButtonTest" to "TurnOff"
end if
Am I doing this right? I still got nothing works in the statement.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Use the icon of button as a conditional statement (if el

Post by SparkOut » Thu Nov 05, 2015 8:10 am

You can certainly do this with the icon id to refer to the it rather than a "name" as such. Otherwise you can check the button's label in that manner.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Use the icon of button as a conditional statement (if el

Post by bn » Thu Nov 05, 2015 8:17 am

Hi Cheong,

try to identify the icon by its id as Sparkout said.

use this code as example

Code: Select all

on mouseUp
   if the icon of button "buttonTest" is the short id of image "turnOn" then
      set the icon of button "buttonTest" to the short id of image "turnOff"
   else 
      set the icon of button "buttonTest" to the short id of image "turnOn"
   end if
end mouseUp
Mind you the id of an image is the short id. This means just the number.

You can set the icon of a button by the name of the image but I don't see a way to ask for the current icon of a button by asking for the name except for using "resolve image"

Kind regards
Bernd

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Use the icon of button as a conditional statement (if el

Post by Klaus » Thu Nov 05, 2015 1:37 pm

You could also use a CHECKBOX with icons, no conditional scripting neccessary at all! :D

Cheong
Posts: 30
Joined: Tue Oct 27, 2015 7:49 am

Re: Use the icon of button as a conditional statement (if el

Post by Cheong » Fri Nov 06, 2015 2:22 am

Thanks Sparkout and Bernd,

Here's the solution I done using your way:

Code: Select all

on mouseUp
   if the icon of button "ButtonTest" is the short id of image "TurnOn.png" then
     set the icon of me to "TurnOff.png"
   end if
end mouseUp
Hi Klaus, I will try it with checkbox with icons also! Thanks for the idea! :D

Post Reply