1

I have a card with a large number of controls on it: 33 buttons, 33 menus, and 33 radio button pairs. Each time a control is used a property of the control changes -- the hilite on one of the radio buttons in each pair is activated, a menu item appears other than the original label (which is 0), and the buttons change color from their default. I want to write a loop that resets all the controls to their default state. The buttons have been labeled RB01 through RB33, the menu items are labeled RM01 through RM33, and the radio button pairs are RR01 through RR33. Also, the ID numbers of the controls are not consecutive. Here's what I have so far:

    on mouseUp
       repeat with x = 1 to 33
          set the backgroundColor of button "RB[x]" to default
          set the Label of button "RM[x]" to 0
          set the highlite of of group "RR[x]" to FALSE
       end repeat
    end mouseUp

The use of "RB[x]" is the problem here and I haven't been able to find anything a good solution despite searching. Is there a way to do this in Livecode or is there a better naming convention for the controls so I could do this in a loop?

credenzamatic
  • 19
  • 1
  • 4

2 Answers2

0

Your solution is very close. The problem is with the use of the [ ] notation, which is reserved for arrays. Use the concatenation operator & instead. Notice that I'm also padding the x with a leading zero if needed. The ( ) forces the concatenated string to be evaluated before the object name.

on mouseUp
   repeat with x = 1 to 33
      if length(x) < 2 then put "0" before x
      set the backgroundColor of button ("RB" & x) to default
      set the Label of button ("RB" & x) to 0
      set the highlite of of group ("RB" & x) to FALSE
   end repeat
end mouseUp
Devin
  • 593
  • 1
  • 3
  • 8
  • I kind of answered my own question and added it below; however, I like your answer better -- far more compact than what I came up with -- and accepted it. Thanks for your help. – credenzamatic Sep 09 '17 at 03:26
0

I went back and studied the id numbers of the controls. While they are not consecutive, they occur in steps of five (e.g. button id 1350, button id 1355, and so on). So then I addressed the change in each control group in a loop much like this:

    repeat x = 1350 to  1515 step 5
       set backgroundColor of button id x to default
    end repeat

Because each loop would draw on different values (based on id numbers), four loops were necessary: one to change the color of the buttons, one to change the labels on the menu buttons, and one for each radio button despite the fact that they were grouped. While this approach works, it is not as efficient as Devin's answer.

credenzamatic
  • 19
  • 1
  • 4