Page 1 of 1

sending same command to multiple cards

Posted: Mon Apr 27, 2015 4:04 pm
by parky0109
Hi All,

I am a complete beginner, not just with LiveCode but with programming full stop. I've been trying to solve all my little problems myself, but may need some help with this. I'm sure there is a very simple solution.

I'm building an clinical health app, which has a number of scoring buttons which are doing identical jobs on multiple cards. All I want to do is create a "reset" button on the front screen to set the hilite of all the buttons to false.

It works as I have set out below, but is there a way of say listing all the cards on one line of script to save unwanted lines of script?

command startPressed

set the hilite of button "Importance0" on card "Goal1" to false
set the hilite of button "Importance0" on card "Goal2" to false
set the hilite of button "Importance0" on card "Goal3" to false
set the hilite of button "Importance0" on card "Goal4" to false
set the hilite of button "Importance0" on card "Goal5" to false
set the hilite of button "Importance0" on card "Goal6" to false
set the hilite of button "Importance0" on card "Goal7" to false

Any help will be much appreciated.

Re: sending same command to multiple cards

Posted: Mon Apr 27, 2015 4:14 pm
by Klaus
Hi parky0109,

1. welcome to the forum! :D

2. Sorry, no one-liner, but you can use a repeat loop:

Code: Select all

...
## Seven different cards, we will create the correct card names in the loop:
repeat with i = 1 to 7
  set the hilite of button "Importance0" OF cd ("Goal" & i) to false
end repeat
...
Please note the brackets around the concatented card name!
This is absolutely neccessary, since the engine will first evaluate the "expression"
inside of the brackets and then use that correct card name.

Please check these great learning resources:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Re: sending same command to multiple cards

Posted: Mon Apr 27, 2015 4:29 pm
by parky0109
Great, thanks Klaus.

So I'm guessing that if I also had "Importance1" "Importance2" and "Importance3" I could add another loop say,

repeat with x = 0 to 3

and have

set the hilite of button ("Importance" & x) OF cd ("Goal" & i) to false

Re: sending same command to multiple cards

Posted: Mon Apr 27, 2015 5:04 pm
by Klaus
Hi parky0109,

you will of course start with 1 in your second loop :D !

You will have to put this inside of the first repeat loop:

Code: Select all

...
repeat with i = 1 to 7
   repeat with x = 1 to 3
     set the hilite of button ("Importance" & x) OF cd ("Goal" & i) to false
  end repeat
end repeat
...
Best

Klaus

Re: sending same command to multiple cards

Posted: Tue Apr 28, 2015 12:50 pm
by parky0109
I used 0-3 as the first button is "Importance0"

Worked great.

Thanks for your help.