Page 1 of 1

If any button...

Posted: Mon Apr 14, 2014 11:28 am
by croivo
I have 116 buttons in my stack all with same labels, but one (randomly choosed) has different label. What I want to do is when I click on a button it search all buttons in my card and changes the label of that one button (with different label) to same label all other buttons have.
I need some code LIKE this:

on mouseUp
if the label of *any* button is "Hide" then
set the label of *that button* to "Show"
else
end if
end mouseUp

Is this possible to do?

Re: If any button...

Posted: Mon Apr 14, 2014 11:35 am
by Klaus
Hi croivo,

no, that is not possible! 8)

Just kidding :D

Sure it is, you will need to do a repeat loop like this:

Code: Select all

on mouseup

  ## Prevent any "flickering":
  lock screen

  ## Loop over ALL buttons on current card:
  repeat with i = 1 to the num of btns
       if the label of btn i = "Hide" then
           set the label of btn i to "Show"
      end if
  end repeat

  unlock screen
end mouseup
Best

Klaus

Re: If any button...

Posted: Mon Apr 14, 2014 11:53 am
by croivo
Thanks! That's what I was looking for...
Is there a way I can restrict the buttons for only certain group? For example, something like this:

Code: Select all

## Prevent any "flickering":
      lock screen
      
      ## Loop over ALL buttons on current card:
      repeat with i = 1 to the num of btns *of group "myGroupWithButtons"*
         if the label of btn i = "Hide" then
            set the label of btn i to "Show"
            set the backgroundcolor of btn i to white
         end if
      end repeat
      unlock screen

Re: If any button...

Posted: Mon Apr 14, 2014 11:57 am
by Klaus
Hi croivo,

you almost had it :D
croivo wrote:

Code: Select all

## Prevent any "flickering":
      lock screen   
      ## Loop over ALL buttons on current card
      ## Correct!
      repeat with i = 1 to the num of btns of group "myGroupWithButtons"

         ## but you need to add the exact "descriptor" every time:
         if the label of btn i of group "myGroupWithButtons" = "Hide" then
            set the label of btn i of group "myGroupWithButtons" to "Show"
            set the backgroundcolor of btn i of group "myGroupWithButtons" to white
         end if
      end repeat
      unlock screen
Best

Klaus

Re: If any button...

Posted: Mon Apr 14, 2014 12:51 pm
by croivo
That's it! Thanks Klaus!