Identify button

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
codes4kids
Posts: 7
Joined: Sat Jun 22, 2019 9:19 pm

Identify button

Post by codes4kids » Thu Nov 03, 2022 2:10 pm

Is it possible to identify a button ID by the icon image ID? Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Identify button

Post by dunbarx » Thu Nov 03, 2022 2:17 pm

Hi.

If I understand what you are asking, the "icon" is a property of a button. So if you had, say, ten buttons, and the icon of one of them was, say, "210012", then this would pick it out:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of buttons
      if the icon of button y = 210012 then
        answer the ID of btn y
        exit repeat
   end repeat
end mouseUp
Craig

EDIT: I beat Klaus to virtually the same handler by two minutes.

HAH!

Anyway, he actually answered the OP's question just a tad better, so I updated my original handler by answering the ID instead of the number.
Last edited by dunbarx on Thu Nov 03, 2022 2:39 pm, edited 1 time in total.

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

Re: Identify button

Post by Klaus » Thu Nov 03, 2022 2:19 pm

Sure, with a repeat loop over all the buttons on the current card, see example (or the complete stack if neccessary)

Code: Select all

...
repeat with i = 1 to the num of btns
  if the ICON of btn i = your_wanted_id_here then
     anwser the ID of btn i
  end if
end repeat
...

codes4kids
Posts: 7
Joined: Sat Jun 22, 2019 9:19 pm

Re: Identify button

Post by codes4kids » Sun Nov 06, 2022 1:46 pm

Thank you dunbarx and Klaus!

Post Reply