Set a random no. of variables from a random no. of items using a loop

Here is what I’d like to do:

In the example script, there are 4 text items. I’m trying to make Applescript count the number of text items, and then create a number of variables equal to the number of text items. In the example, there’d be 4 variables, e.g.

var1=“eenie”
var2=“meenie”
var3=“miney”
var4=“moe”

A text string with 3 text items would set 3 variables, a text string with 5 text would set 5 variables, etc.

is there a way to do this? Do I have to use a repeat loop, or is there another way around it?

set AppleScript's text item delimiters to the " "
set theseWords to "eenie meenie miney moe"
repeat with i from 1 to count of text items of theseWords
	if text item i of theseWords = "moe" then
		display dialog "Here it is: moe"
	end if
end repeat
set AppleScript's text item delimiters to the ""

I’m not sure where the randomness comes it, but you can use the words property of the class text.

set theseWords to "eenie meenie miney moe"

repeat with i from 1 to count of words of theseWords
	display dialog "Here it is: " & word i of theseWords
end repeat

Hi.

It’s not possible to set and use a random number of variables ” unless you know the maximum number beforehand and are willing to write a lot of ‘if’ clauses to cover every eventuality.

For your purposes, you’ll normally use just one variable: to store the list containing the items. It’s also common for a single variable to be set to each of the items in turn during a repeat. (This is for clarity and/or to save getting each item from the list several times when several tests need to be performed on it.) There is, of course, nothing to stop you using separate variables for individual values in the list which have particular significance in the script.