Page 1 of 1

send message to each object in this card?

Posted: Wed Sep 09, 2009 10:59 pm
by dochawk
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

Posted: Thu Sep 10, 2009 5:51 am
by Janschenkel
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.

Posted: Fri Sep 11, 2009 1:16 am
by dochawk
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

Posted: Mon Sep 14, 2009 9:56 pm
by TodayIsTheDay
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...

Posted: Mon Sep 14, 2009 11:33 pm
by dochawk
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

Posted: Mon Sep 14, 2009 11:37 pm
by bn
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