Very basic question - variable variable names

Hi! I am a noob. :')

I’m trying to repeat through a list of numbers and then create variable names by appending the number to a string on each iteration.

Like this:


repeat with i from 1 to amountOfFavourites
	
	copy "location" & i to the end of favList
	
end repeat

I have variables called location1, location2 and so on, and I want their values added to the list. I guess I’m not searching the web correctly, because I can’t find any info on it.

Argh, woe is me, the noobie.

Anyhoo, this is my first post on this forum, and I hope to contribute to it in the future. I’m a PHP, ActionScript, Javascript experienced web developer. And I’m planning on developing several small and free ‘handies’ for OS X.

I’m working on an FTP droplet now.

Thanks! :')

Okay, small progress:


set location1 to "hey"
set location2 to "you"

global location1
global location2

repeat with i from 1 to favCount
	
	run script "set this_item to location" & i
	
	copy this_item to the end of favList
	
end repeat

The only problem is that the variable does not exist in the script that tries to set this_item to the value of location1 or location2.

I am thinking it has to do with variable scoping, but making the variables global doesn’t help!

I’m sure I’m overlooking something very basic here…

In AppleScript, the names of variables are simply an arrangement between you and the compiler. You can’t change them at run time or refer to them from run-time data.

I can’t quite see what you’re trying to achieve, otherwise I’d be a little more helpful with alternative code. :slight_smile:

Thanks for the heads up!

I found a workaround for my problem. I’m so used to Actionscript and PHP that I keep thinking in the wrong terms ;')