Re: referencing a variable from another?
Re: referencing a variable from another?
- Subject: Re: referencing a variable from another?
- From: Steven Angier <email@hidden>
- Date: Sat, 01 Feb 2003 16:47:59 +1100
On 1/2/03 1:24 PM, "James Burns" <email@hidden> wrote:
>
I'm just starting out relearning AppleScript, Please bear with me.
>
>
I'm trying to use one variable, which contains the name of a second
>
variable, to change the value of the "named" variable. Make sense?
>
>
Here's the snippet I'm working on:
>
>
...
>
>
set RGBname to "SaveRGBImagesPrefix"
>
set FirstFrame to "FirstFrame"
>
set LastFrame to "LastFrame"
>
set FrameStep to "FrameStep"
>
>
set stuffToGet to {RGBname, FirstFrame, LastFrame, FrameStep}
>
log stuffToGet
>
repeat with x in stuffToGet
>
set searchWord to x
>
try
>
set text item delimiters to return
>
set i to text items of fileContents
>
repeat with foundIt in i
>
if foundIt contains searchWord then
>
log "Found line is " & foundIt
>
set text item delimiters to " "
>
set cleaned to (text items 2 thru -1 of foundIt) as string
>
log cleaned
>
>
HERE"S WHERE I NEED TO ASSIGN THE VALUE HELD IN CLEANED TO THE VARIABLE
>
CONTAINED IN SEARCHWORD
You have to work with references for this:
--initialise variables
set {a, b, c, d} to {1, 2, 3, 4}
--build a list of references to the variables
set theList to {ref a, ref b, ref c, ref d}
--method 1: traverse by index
repeat with i from 1 to length of theList
set contents of (item i of theList) to (item i of theList) + 4
end repeat
--method 2: traverse by reference
repeat with theItem in theList
set contents of (contents of theItem) to (contents of theItem) + 4
end repeat
return {a, b, c, d}
--------
Method 1 is faster than method 2 on longer lists -- and is probably easier
to get your head around.
Hope this helps.
Steven Angier
Macscript.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.