sending same command to multiple cards

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
parky0109
Posts: 3
Joined: Mon Apr 27, 2015 3:51 pm

sending same command to multiple cards

Post by parky0109 » Mon Apr 27, 2015 4:04 pm

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.

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

Re: sending same command to multiple cards

Post by Klaus » Mon Apr 27, 2015 4:14 pm

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

parky0109
Posts: 3
Joined: Mon Apr 27, 2015 3:51 pm

Re: sending same command to multiple cards

Post by parky0109 » Mon Apr 27, 2015 4:29 pm

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

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

Re: sending same command to multiple cards

Post by Klaus » Mon Apr 27, 2015 5:04 pm

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

parky0109
Posts: 3
Joined: Mon Apr 27, 2015 3:51 pm

Re: sending same command to multiple cards

Post by parky0109 » Tue Apr 28, 2015 12:50 pm

I used 0-3 as the first button is "Importance0"

Worked great.

Thanks for your help.

Post Reply