send message to each object in this card?

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
dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

send message to each object in this card?

Post by dochawk » Wed Sep 09, 2009 10:59 pm

It's been a while (uhh, 1994, I think) since I spent time with hypercard, and now I'm reinventing an application I wrote in the early 90s, as I haven't found a way read any of my mac diskettes, and can't get the one mac with a probably working drive to work at all (and it has these stacks on hard drive!) *sigh*

Anyway, it seems to me that I used to use a structure such as

Code: Select all

send doIt to each field in this card
but

Code: Select all

each
seems to only apply to chunks/containers.

I can see that

Code: Select all

repeat with count = 1 to the number of fields
  send doIt to field count
end repeat
but that seems awkward

hawk

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Thu Sep 10, 2009 5:51 am

There's no repeat for each field loop structure, nor is there a way to broadcast messages to multiple controls at the same time. There was nothing like that in HyperCard either. So I'm afraid you'll have to use the repeat with i = 1 to the number of fields approach...

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

Post by dochawk » Fri Sep 11, 2009 1:16 am

Thanks. I wonder what I'm remembering (Could it have been SuperCard? I had to switch a project to it for multiple windows before they were introduced in hypercard).

thanks

hawk

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Mon Sep 14, 2009 9:56 pm

Can one of you guys possibly post an example of this?

I'm following the idea but not the code.

For instance if I wanted to change the background color of multiple objects or show or not show the border...

dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

Post by dochawk » Mon Sep 14, 2009 11:33 pm

The code snippit above would do that.

Just replace the "send doit" with "set the color of field i to red" (or whatever the grammar is on that--Last time I dealt with this, we didn't even have gray :)

and if you want to select them all, something like

Code: Select all

put empty into myList

repeat with i = 1 to the number of fields
   if the short name of  field i <> "Label Field" then
       put "and field " & the short name of field i & after myList
    end if
end repeat

--but there is are extra pieces at the ends of our string
delete the first word of myList

select mylist
I just used this for a script to to select, group, shove back and make unselectable all of the labels and rectangles on an arbitrary card.

hawk

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon Sep 14, 2009 11:37 pm

you could make a stack with one card and 2 fields and 2 buttons. Set the script of one button to

Code: Select all

on mouseUp
   repeat with i = 1 to the number of controls
      put the long id of control i into myControl
      if word 1 of myControl is "field" then set the backgroundcolor of myControl to green
      if word 1 of myControl is "button" then set the backgroundcolor of myControl to red
   end repeat
end mouseUp
This way you will set the backgroundcolor of every field to green and the backgroundcolor of every button to red. Of course you could adapt this script to fields only, then you could say repeat with i = 1 to the number of fields and so on.
Insert the word breakpoint in the script before the repeat loop and look what goes into the variable myControl. Under the menu development you would have to turn Script Debug Mode on.
regards
Bernd

Post Reply