Page 1 of 1

Putting values into globals via a repeat loop

Posted: Wed Oct 14, 2009 7:35 pm
by gyroscope
Hi, sorry to cover old ground; I seem to remember this being mentioned a couple of months ago but can't find the post...

I have a set of 48 global variables and a list of up to 48 words.

One would think the following would work (although I understand why it doesn't, if that makes sense):

Code: Select all


global gWordCount01
global gw1,gw2,gw3,gw4,gw5,gw6,gw7,gw8,gw9,gw10,gw11,gw12,gw13,gw14,gw15,gw16,gw17,gw18,gw19,gw20,gw21,gw22,gw23,gw24
global gw25,gw26,gw27,gw28,gw29,gw30,gw31,gw32,gw33,gw34,gw35,gw36,gw37,gw38,gw39,gw40,gw41,gw42,gw43,gw44,gw45,gw46,gw47,gw48

on mouseUp
repeat with tWords= 1 to gWordCount
put tWords into (gw&tWords)
end repeat
end mouseUp
Is there a neat scripting solution to what I'm after, please :?:

:)

Additional question: is there a way to script to make a local variable a global one :?:

Posted: Wed Oct 14, 2009 7:56 pm
by bn
Hi Gyroscope,

try:

Code: Select all

on mouseUp
   repeat with tWords= 1 to gWordCount01
      do "put tWords into gw" & tWords & ""
   end repeat 
end mouseUp
of course with all your global variables declared.
Why dont you use an array in a custom property? Seems to be a lot easier.
regards
Bernd

Posted: Wed Oct 14, 2009 9:06 pm
by gyroscope
Ah yes, I remember now Bernd, thank you. I'll staple that solution into my mind...
Why dont you use an array in a custom property? Seems to be a lot easier.
I still shy away from custom properties; I'm determined to make it click with me one day.

:)

Posted: Thu Oct 15, 2009 10:48 pm
by Mark Smith
You could also have a global array:

Code: Select all

global tw

on mouseUp 
  repeat with tWords = 1 to gWordCount 
    put tWords into tw["gw" & tWords]
  end repeat 
end mouseUp
Best,

Mark Smith

Posted: Sat Oct 17, 2009 10:21 pm
by gyroscope
That's useful, thank you Mark.

:)