If any 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
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

If any button...

Post by croivo » Mon Apr 14, 2014 11:28 am

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?

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

Re: If any button...

Post by Klaus » Mon Apr 14, 2014 11:35 am

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

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: If any button...

Post by croivo » Mon Apr 14, 2014 11:53 am

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

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

Re: If any button...

Post by Klaus » Mon Apr 14, 2014 11:57 am

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

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: If any button...

Post by croivo » Mon Apr 14, 2014 12:51 pm

That's it! Thanks Klaus!

Post Reply