Newbie needs help with script (display randomized numbers)

Hi I’m new to script. I want to write a program for a memory test that displays a single randomly chosen digit for any amount of time I wish, and then repeat this (with different random digits) as many times as I wish. Afterwards I would like to test one’s memory by having an imput box displayed where one can enter the digits. The program would then confirm if the answer is correct.

I would love to expand this to have a menu where I can choose from all sorts of “memory games,” but at the moment I’d be happy with the former.

I’ve been looking around the web, and this site an haven’t found the specific examples that could help me with writing this program.

Could someone give me some tips, pointers, examples, etc.?

Model: iMac G%
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

Try this for openers; it will give you some ideas on how to get there:

repeat
	set HoldFor to 2 -- how long to hold each number
	set RepNum to 5 -- how many successive numbers to display
	set Vals to {}
	set digits to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	
	repeat RepNum times
		set thisDigit to some item in digits -- this is easier than using the random function
		display dialog thisDigit buttons {"Cancel"} giving up after HoldFor -- cancel quits the loop
		set end of Vals to thisDigit
	end repeat
	
	delay 1 -- delay before presenting answer box
	
	display dialog "Please enter the " & RepNum & " digits below" default answer "" buttons {"Cancel", "Done"} default button "Done"
	set theReply to characters of text returned of result
	repeat with aNum in theReply
		set contents of aNum to contents of aNum as number -- just to have both the stored values and the original data as numbers
	end repeat
	
	set Errors to 0
	repeat with j from 1 to RepNum
		if item j of Vals ≠ item j of theReply then set Errors to Errors + 1
	end repeat
	display dialog "You made " & Errors & " errors. Do you want to see the lists?" buttons {"Yes", "No"}
	set Btn to button returned of result
	if Btn = "Yes" then display dialog ("The values were: " & Vals as string) & return & "You entered these: " & theReply as string buttons {"OK"}
	display dialog "Do you want to go again?" buttons {"No", "Yes"}
	if button returned of result is "No" then exit repeat
	delay 1 -- delay to prevent immediate new number
end repeat

That’s fantastic - thanks so much for your help. I’m going to run this, learn from it and se how far I can take it.

Don’t hesitate to ask questions - that’s what this forum is about.

By the way - it occurs to me looking at this again that the line: set digits to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
should be right after set Vals to {} (outside the repeat loop). There is no need to redefine digits every time. I’ve edited the script above to reflect that. Also, if you wanted to use letters instead of numbers, some changes would be required as shown below:

repeat
	set HoldFor to 2 -- how long to hold each letter
	set RepNum to 5 -- how many successive letters to display
	set Vals to {}
	set Letters to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
	
	repeat RepNum times
		set aLetter to some item in Letters
		display dialog aLetter buttons {"Cancel"} giving up after HoldFor -- cancel quits the loop
		set end of Vals to aLetter
	end repeat
	
	delay 1 -- delay before presenting answer box
	
	display dialog "Please enter the " & RepNum & " letters below" default answer "" buttons {"Cancel", "Done"} default button "Done"
	set theReply to characters of text returned of result
	
	set Errors to 0
	repeat with j from 1 to RepNum
		if item j of Vals ≠ item j of theReply then set Errors to Errors + 1
	end repeat
	display dialog "You made " & Errors & " errors. Do you want to see the lists?" buttons {"Yes", "No"}
	if button returned of result = "Yes" then display dialog ("The values were: " & Vals as string) & return & "You entered these: " & theReply as string buttons {"OK"}
	display dialog "Do you want to go again?" buttons {"No", "Yes"}
	if button returned of result is "No" then exit repeat
	delay 1 -- delay to prevent immediate new letter
end repeat

You could also do this:

property letters : paragraphs of (do shell script "/usr/bin/jot -c 26 A Z")
--Or
property digits : paragraphs of (do shell script "/usr/bin/jot 20 1 20")

I had never encountered jot before - a great little tool. Thanks!

Thanks for you help guys. I’m new to programming, so it is taking me some time to absorb all of this. I did create a “menu” where you can choose if you want to test 5, 7, or 9 digits, but the script editor says that I can’t create more than three buttons. I’d like to include 11, 13, and 15 digits as well. Do you guys know how to create more buttons beyond what scripteditor accepts?

set RepNum to (choose from list {5, 7, 9, 11, 13, 15} with prompt "How many digits do you want to try?" default items {5} without multiple selections allowed) as number

Unfortunately, “giving up after…” doesn’t understand fractional seconds, but you can choose integer presentation times:

set HoldFor to (choose from list {1, 2, 3} with prompt "How long do you need per digit?" default items {1} without multiple selections allowed) as number
display dialog "Sample time of " & HoldFor & " seconds" giving up after HoldFor

OK I did some modifications and compiled it. I’ve tested it and it seems to work. What do you guys think?


display dialog "MemoryBuilder Version 1.0"
delay 1
repeat
	display dialog "Which test would you like?" buttons {"Number-Span", "Letter-Span", "Exit"}
	set Btn to button returned of result
	if Btn = "Number-Span" then repeat
		set HoldFor to (choose from list {1, 2, 3} with prompt "How long do you need per digit?" default items {1} without multiple selections allowed) as number
		display dialog "Sample time of " & HoldFor & " seconds" giving up after HoldFor -- how long to hold each number
		set RepNum to (choose from list {5, 7, 9, 11, 13, 15} with prompt "How many digits do you want to try?" default items {5} without multiple selections allowed) as number -- how many successive numbers to display
		set Vals to {}
		set digits to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
		display dialog "Prepare to be tested!"
		delay 2
		repeat RepNum times
			set thisDigit to some item in digits -- this is easier than using the random function
			display dialog thisDigit buttons {"Cancel"} giving up after HoldFor -- cancel quits the loop
			set end of Vals to thisDigit
		end repeat
		delay 1 -- delay before presenting answer box
		display dialog "Please enter the " & RepNum & " digits below" default answer "" buttons {"Cancel", "Done"} default button "Done"
		set theReply to characters of text returned of result
		repeat with aNum in theReply
			set contents of aNum to contents of aNum as number -- just to have both the stored values and the original data as numbers
		end repeat
		set Errors to 0
		repeat with j from 1 to RepNum
			if item j of Vals ≠ item j of theReply then set Errors to Errors + 1
		end repeat
		display dialog "You made " & Errors & " errors. Do you want to see the lists?" buttons {"Yes", "No"}
		set Btn to button returned of result
		if Btn = "Yes" then display dialog ("The values were: " & Vals as string) & return & "You entered these: " & theReply as string buttons {"OK"}
		display dialog "Do you want to go again?" buttons {"No", "Yes"}
		if button returned of result is "No" then exit repeat
		delay 1 -- delay to prevent immediate new number
	end repeat
	if Btn = "Letter-Span" then repeat
		set HoldFor to (choose from list {1, 2, 3} with prompt "How long do you need per letter?" default items {1} without multiple selections allowed) as number
		display dialog "Sample time of " & HoldFor & " seconds" giving up after HoldFor -- how long to hold each letter
		set RepNum to (choose from list {5, 7, 9, 11, 13, 15} with prompt "How many Letters do you want to try?" default items {5} without multiple selections allowed) as number -- how many successive numbers to display
		set Vals to {}
		set Letters to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
		display dialog "Prepare to be tested!"
		delay 2
		repeat RepNum times
			set aLetter to some item in Letters
			display dialog aLetter buttons {"Cancel"} giving up after HoldFor -- cancel quits the loop
			set end of Vals to aLetter
		end repeat
		delay 1 -- delay before presenting answer box
		display dialog "Please enter the " & RepNum & " letters below" default answer "" buttons {"Cancel", "Done"} default button "Done"
		set theReply to characters of text returned of result
		set Errors to 0
		repeat with j from 1 to RepNum
			if item j of Vals ≠ item j of theReply then set Errors to Errors + 1
		end repeat
		display dialog "You made " & Errors & " errors. Do you want to see the lists?" buttons {"Yes", "No"}
		if button returned of result = "Yes" then display dialog ("The values were: " & Vals as string) & return & "You entered these: " & theReply as string buttons {"OK"}
		display dialog "Do you want to go again?" buttons {"No", "Yes"}
		if button returned of result is "No" then exit repeat
		delay 1 -- delay to prevent immediate new letter
	end repeat
	if Btn = "Exit" then exit repeat
end repeat

Excellent so far. Letters are definitely harder to remember (at least for me). I learned something too - I didn’t know that AppleScript would test “A” to be equal to “a”, but it does, so your test accepts lower case for the answer even though upper case was given. If you want to convert from lower to upper case, this works:

set Ltr to "a"
ASCII character of ((ASCII number Ltr) - 32)
--> "A"

The only other thing (which I leave as an exercise for your skill building) is that you could have avoided the two entirely separate codes for Letters and Numbers. If you examine the two, you’ll see that very little changes, i.e. one uses “digits” the other “letters” in dialog text and they use different lists for the variables. The variables “aLetter” and “thisDigit” could just as well be “anItem” for both of them, and the initial choice of lists would set things up, i.e. if digits, then set theList to digits else set theList to Letters where anItem in theList is then used in the main loop.

It’s easy to substitute words in a string (like a dialog prompt) by concatination so you can predefine key words:

set Btn to button returned of (display dialog "Choose a button" buttons {"A", "B"})
display dialog "You chose button " & Btn & "!" buttons {"OK"} default button "OK"

Finally, to speed things up, no constants like the letters list or the numbers list should be inside a repeat (I know, I did it too), so lump them all outside all repeats. Once they’re defined, they’re defined.

I’ll stop there - excellent beginning.

OK, I’m going to try and simplify it and post here when I’ve got it. I’m also going to try and set the program up so that when you enter the answer, it must be reversed, and then it is checked to see if it matches the orginal set in reverse.

Then you should know about the word “reverse”:

set myString to "ABCDE"
(reverse of characters of myString) as string
--> "EDCBA"

OK I am trying to do the reverse order set first, but I keep getting an applescript error with highlighting the second “item j” at the bottom in this protion of the script. I suppose it has something to do with not defining “ReVals” and “ReReply” in the proper places of the loops - or am I wrong?

I am just tryin it with the number sequence first, that way I can redo the script to switch back and forth between numbers and letters like you suggested earlier.


set Vals to {}
		set ReVals to (reverse of characters of Vals) as string
		display dialog "Prepare to be tested!"
		delay 2
		repeat RepNum times
			set thisDigit to some item in digits -- this is easier than using the random function
			display dialog thisDigit buttons {"Cancel"} giving up after HoldFor -- cancel quits the loop
			set end of Vals to thisDigit
		end repeat
		delay 1 -- delay before presenting answer box
		display dialog "Please enter the " & RepNum & " digits below" default answer "" buttons {"Cancel", "Done"} default button "Done"
		set theReply to characters of text returned of result
		set ReReply to (reverse of characters of theReply) as string
		repeat with aNum in ReReply
			set contents of aNum to contents of aNum as number -- just to have both the stored values and the original data as numbers
		end repeat
		set Errors to 0
		repeat with j from 1 to RepNum
			if item j of ReVals ≠ item j of ReReply then set Errors to Errors + 1




Some thoughts.

property theNumbers : paragraphs of (do shell script "/usr/bin/jot 10 0 9")
property theLetters : paragraphs of (do shell script "/usr/bin/jot -c 26 A Z")
property timeLimit : 3
property rep : 5

repeat
	display dialog "Which test would you like?" buttons {"Cancel", "Letters", "Numbers"} default button 3
	
	if button returned of result is "Numbers" then
		set theList to a reference to theNumbers
		set theType to "digit"
	else
		set theList to a reference to theLetters
		set theType to "letter"
	end if
	
	repeat
		display dialog "Time limit (in seconds) per " & theType & ":" default answer timeLimit buttons {"Cancel", "Test Time Limit", "Continue"} default button 3
		set {text returned:timeLimit, button returned:nextAction} to result
		
		try
			set timeLimit to timeLimit as integer
			if result is less than 1 then error
			
			if nextAction is "Continue" then
				exit repeat
			else
				display dialog "Sample time limit of " & timeLimit & " seconds." buttons {"OK"} giving up after timeLimit
			end if
		end try
	end repeat
	
	choose from list {5, 7, 9, 11, 13, 15} with prompt "How many " & theType & "s do you want to try?" default items {rep}
	if result is not false then
		set rep to result as integer
	else
		error number -128 -- User canceled
	end if
	
	display dialog "Testing will begin after the beeps."
	delay 2
	beep 2
	
	set testList to {}
	repeat rep times
		set testList's end to some item in theList
		display dialog (result) buttons {"Cancel"} giving up after timeLimit
	end repeat
	
	delay 1
	display dialog "Please enter the " & rep & space & theType & "s in reverse order:" default answer "" buttons {"Cancel", "Done"} default button 2
	set answerList to characters of text returned of result
	set testList to reverse of testList
	
	set errorCount to 0
	repeat with i from 1 to rep
		if item i of answerList ≠ item i of testList then set errorCount to errorCount + 1
	end repeat
	
	display dialog "You made " & errorCount & " errors." buttons {"View Lists", "Quit", "Retry"} default button 3
	set nextAction to button returned of result
	
	if result is "View Lists" then
		set ASTID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {", "}
		
		display dialog ("Correct values: " & (testList as text) & return & "Your answers:  " & (answerList as text)) buttons {"Quit", "Retry"}
		set nextAction to button returned of result
		set AppleScript's text item delimiters to ASTID
	end if
	
	if nextAction is "Quit" then exit repeat
end repeat

Anyone for words, then? (Some of the words produced by the routine below might look a bit suspect - but then I suppose it all makes for a more interesting memory test…) Me? I’m just quite pleased when I can remember my name. :wink:

property memDesc : {"Seconds to memorise each word:" & tab & tab, ¬
	"Words to memorise each round:" & tab & tab, ¬
	"Number of characters in each word:" & tab}
property memVal : {2, 4, 5}
property upperLimit : {30, 30, 24}
property lowerLimit : {1, 2, 3}

to setup_game()
	set selected_Item to 1
	set checkChar to «data utxt2713» as Unicode text
	repeat
		tell memVal's items
			set diffRating to 30 * (item 3) * (item 2) / (item 1) div 3
			repeat with i from 1 to count
				set item i to memDesc's item i & item i
			end repeat
			set l to it
		end tell
		set c to choose from list l with prompt "Set the difficulty level for this game:" with title ¬
			"Current Difficulty Rating: " & diffRating default items l's item selected_Item ¬
			OK button name "Edit" cancel button name "Play"
		if c is false then exit repeat
		tell c's item 1 to repeat with selected_Item from 1 to count l
			if it is l's item selected_Item then exit repeat
		end repeat
		set btn to "+"
		repeat
			set btn to button returned of (display dialog memDesc's item selected_Item & ¬
				memVal's item selected_Item buttons {checkChar, "-", "+"} default button btn)
			if btn is checkChar then exit repeat
			tell memVal's item selected_Item to if btn is "+" then
				if it < upperLimit's item selected_Item then ¬
					set memVal's item selected_Item to it + 1
			else if it > lowerLimit's item selected_Item then
				set memVal's item selected_Item to it - 1
			end if
		end repeat
	end repeat
end setup_game

to play_game()
	set {showTime, wordCount, charCount} to memVal
	set wordList to paragraphs of (do shell script "awk " & quoted form of ¬
		("length == " & charCount) & " /usr/share/dict/words | tr \"A-Z\" \"a-z\"")
	set roundNum to 1
	repeat
		set origList to {}
		display dialog "Ready to start?" with title "Round " & roundNum
		repeat with wordNum from 1 to wordCount
			set w to some item of wordList
			set origList's end to w
			display dialog return & tab & tab & tab & tab & w with title ¬
				"Round " & roundNum & " - Word " & wordNum & " of " & ¬
				wordCount buttons {"Cancel"} giving up after showTime
		end repeat
		set entryForm to ""
		repeat wordCount - 1 times
			set entryForm to entryForm & return
		end repeat
		set entryList to paragraphs 1 thru wordCount of (text returned of (display dialog "Please list the " & ¬
			wordCount & " words in the correct order:" default answer entryForm) & entryForm)
		set errorList to {}
		repeat with i from 1 to wordCount
			set origWord to origList's item i
			set entryWord to entryList's item i
			if origWord is not entryWord then set errorList's end to origWord & tab & tab & entryWord
		end repeat
		set correctCount to wordCount - (count errorList)
		set roundNum to roundNum + 1
		set continueBtn to "Round " & roundNum & "."
		if correctCount is wordCount then
			set btns to {"Cancel", continueBtn}
		else
			set btns to {"Cancel", "Show Errors", continueBtn}
		end if
		set btn to button returned of (display dialog "Correct answers: " & (correctCount * 100 / wordCount + 0.5) ¬
			div 1 & "% (" & correctCount & " of " & wordCount & ")." buttons btns default button 2)
		if btn is "Show Errors" then
			choose from list errorList with prompt "Original" & tab & tab & ¬
				"Entered" OK button name continueBtn with empty selection allowed
			if result is false then return
		end if
	end repeat
end play_game

setup_game()
play_game()

You’re lucky then that your name’s only three letters, Kai - mine is four, so I’ve always had to struggle. :lol:

Nice script, but I find the game impossible - memorizing a bunch of strange words is really tough given that I have to think for a moment about near relative’s names.

Wow you guys are scripting wizzards. It’s going to take me a while to look at the code and learn it.

I noticed that the word game code seems to retrieve the words from the dictionary. Is that right?

I’m going to see if I can take it and turn it around so that it generates number-words like “90201” or “68493” and see how many number-words one can remember.

Thanks for all your help guys.

OK I have some ideas:

I’m trying to take Kai’s program and replace the words with strings of numbers.

Since Kai uses the dictionary as a ready list of numbers, it would make sense to replace this piece of code


set wordList to paragraphs of (do shell script "awk " & quoted form of ¬
       ("length == " & memVal's item -1) & " /usr/share/dict/words | tr \"A-Z\" \"a-z\"")

with something very similar but calling stings of numbers from some program. Alas, I don’t know of such a program.

Now, I experimented with that little piece of jot code that Bruce provided ealier


property digits : paragraphs of (do shell script "/usr/bin/jot 10 0 9")

and I found that it called the single digits up. I thought, “well, why not just list the range of numbers in the jot code differently to get strings of numbers to be called?” So I tried the following:


set wordList to paragraphs of (do shell script "/usr/bin/jot 999999999999999999999899 100 999999999999999999999999") -- This is where I have to change words to numbers.

I chose the range of numbers to be from strings of three digits to strings of 24 digits. Now if I run Kai’s program with this new piece of code, I get black dialogs. Is this due to the dialog box not being able to handle longer strings of numbers, or just a plain foul-up on my part with the code?

Hi ATST. Since numerical strings are a whole lot easier to produce (no spelling considerations, for one thing), it might just be simpler to create the ‘words’ on the fly - as in this modified version of the above script:

property memDesc : {"Seconds to see each word:" & tab, ¬
	"Words in each round:" & tab & tab, ¬
	"Length of each word:" & tab & tab, ¬
	"Words made up of:" & tab & tab}
property memVal : {2, 4, 3, "Characters"}
property upperLimit : {30, 30, 24}

to setup_game()
	set selected_Item to 1
	set checkChar to «data utxt2713» as Unicode text
	repeat
		tell memVal's items
			set diffRating to 10 + 30 * (item 3) * (item 2) / (item 1) div 3
			repeat with i from 1 to count
				set item i to memDesc's item i & item i
			end repeat
			set l to it
		end tell
		set c to choose from list l with prompt "Set your preferences for this game:" with title ¬
			"Current Difficulty Rating: " & diffRating default items l's item selected_Item ¬
			OK button name "Edit" cancel button name "Play"
		if c is false then exit repeat
		tell c's item 1 to repeat with selected_Item from 1 to count l
			if it is l's item selected_Item then exit repeat
		end repeat
		if selected_Item is 4 then
			set memVal's item selected_Item to button returned of (display dialog memDesc's item selected_Item ¬
				buttons {"Numbers", "Characters"} default button memVal's item selected_Item)
		else
			set btn to "+"
			repeat
				set btn to button returned of (display dialog memDesc's item selected_Item & ¬
					memVal's item selected_Item buttons {checkChar, "-", "+"} default button btn)
				if btn is checkChar then exit repeat
				tell memVal's item selected_Item to if btn is "+" then
					if it < upperLimit's item selected_Item then ¬
						set memVal's item selected_Item to it + 1
				else if it > 1 then
					set memVal's item selected_Item to it - 1
				end if
			end repeat
		end if
	end repeat
end setup_game

to play_game()
	set {showTime, wordCount, charCount, wordType} to memVal
	set wordChars to wordType is "Characters"
	if wordChars then
		set wordList to paragraphs of (do shell script "awk " & quoted form of ¬
			("length == " & charCount) & " /usr/share/dict/words | tr \"A-Z\" \"a-z\"")
	else
		set charList to "0123456789"
	end if
	set roundNum to 1
	repeat
		set origList to {}
		display dialog "Ready to start?" with title "Round " & roundNum
		repeat with wordNum from 1 to wordCount
			if wordChars then
				set w to some item of wordList
			else
				set w to ""
				repeat charCount times
					set w to w & some character of charList
				end repeat
			end if
			set origList's end to w
			display dialog return & tab & tab & tab & tab & w with title ¬
				"Round " & roundNum & " - Word " & wordNum & " of " & ¬
				wordCount buttons {"Cancel"} giving up after showTime
		end repeat
		set entryForm to ""
		repeat wordCount - 1 times
			set entryForm to entryForm & return
		end repeat
		set entryList to paragraphs 1 thru wordCount of (text returned of (display dialog "Please list the " & ¬
			wordCount & " words in the any order:" default answer entryForm) & entryForm)
		set errorList to {}
		repeat with i from 1 to wordCount
			set origWord to origList's item i
			if origWord is in entryList then
				repeat with entryWord in entryList
					if origWord is entryWord's contents then
						set entryWord's contents to false
						exit repeat
					end if
				end repeat
				set origList's item i to false
			end if
		end repeat
		set origList to origList's every Unicode text
		set entryList to entryList's every Unicode text
		set errorCount to count origList
		repeat with i from 1 to errorCount
			set errorList's end to origList's item i & tab & tab & entryList's item i
		end repeat
		set correctCount to wordCount - errorCount
		set roundNum to roundNum + 1
		set continueBtn to "Round " & roundNum & "."
		if correctCount is wordCount then
			set btns to {"Cancel", continueBtn}
		else
			set btns to {"Cancel", "Show Errors", continueBtn}
		end if
		set btn to button returned of (display dialog "Correct answers: " & (correctCount * 100 / wordCount + 0.5) ¬
			div 1 & "% (" & correctCount & " of " & wordCount & ")." buttons btns default button 2)
		if btn is "Show Errors" then
			choose from list errorList with prompt "Questions" & tab & tab & ¬
				"Answers" OK button name continueBtn with empty selection allowed
			if result is false then return
		end if
	end repeat
end play_game

setup_game()
play_game()

Edit 1: Routine adapted to offer the use of both regular and numerical words (see discussion below).
Edit 2: Modified to allow answers in any order (blame Adam - see below).

Hi Kai.

I want to combine your wordgame and numbergame together. I noticed that the first half the the relative programs are exactly the same, so I would only need to slightly alter the second half.

So I came up with this code:


property memDesc : {"Seconds to memorise each word or number-string:" & tab & tab, ¬
	"Number of words or number-strings to memorise each round:" & tab & tab, ¬
	"Number of characters or digits in each word or number-string:" & tab}
property memVal : {2, 4, 5}
property upperLimit : {30, 30, 24}
property lowerLimit : {1, 2, 3}

to setup_game()
	set selected_Item to 1
	set checkChar to «data utxt2713» as Unicode text
	repeat
		tell memVal's items
			set diffRating to 30 * (item 3) * (item 2) / (item 1) div 3
			repeat with i from 1 to count
				set item i to memDesc's item i & item i
			end repeat
			set l to it
		end tell
		set c to choose from list l with prompt "Set the difficulty level for this game:" with title ¬
			"Current Difficulty Rating: " & diffRating default items l's item selected_Item ¬
			OK button name "Edit" cancel button name "Play"
		if c is false then exit repeat
		tell c's item 1 to repeat with selected_Item from 1 to count l
			if it is l's item selected_Item then exit repeat
		end repeat
		set Btn to "+"
		repeat
			set Btn to button returned of (display dialog memDesc's item selected_Item & ¬
				memVal's item selected_Item buttons {checkChar, "-", "+"} default button Btn)
			if Btn is checkChar then exit repeat
			tell memVal's item selected_Item to if Btn is "+" then
				if it < upperLimit's item selected_Item then ¬
					set memVal's item selected_Item to it + 1
			else if it > lowerLimit's item selected_Item then
				set memVal's item selected_Item to it - 1
			end if
		end repeat
	end repeat
end setup_game

to play_game()
	set {showTime, wordCount, charCount} to memVal
	set theWords to paragraphs of (do shell script "awk " & quoted form of ¬
		("length == " & memVal's item -1) & " /usr/share/dict/words | tr \"A-Z\" \"a-z\"")
	set theNumbers to "0123456789"
	set roundNum to 1
	
	display dialog "Which game would you like to play?" buttons {"Words", "Number-String", "Cancel"} default button 3
	
	if button returned of result is "Words" then
		set theList to a reference to theWords
		set theType to "word"
	else
		set theList to a reference to theNumbers
		set theType to "number"
	end if
	repeat
		set origList to {}
		display dialog "Ready to start?" with title "Round " & roundNum
		repeat with wordNum from 1 to wordCount
			set w to some item of theList
			set origList's end to w
			display dialog return & tab & tab & tab & tab & w with title ¬
				"Round " & roundNum & " - Word " & wordNum & " of " & ¬
				wordCount buttons {"Cancel"} giving up after showTime
		end repeat
		set entryForm to ""
		repeat wordCount - 1 times
			set entryForm to entryForm & return
		end repeat
		set entryList to paragraphs 1 thru wordCount of (text returned of (display dialog "Please list the " & ¬
			wordCount & theType & " in the correct order:" default answer entryForm) & entryForm)
		set errorList to {}
		repeat with i from 1 to wordCount
			set origWord to origList's item i
			set entryWord to entryList's item i
			if origWord is not entryWord then set errorList's end to origWord & tab & tab & entryWord
		end repeat
		set correctCount to wordCount - (count errorList)
		set roundNum to roundNum + 1
		set continueBtn to "Round " & roundNum & "."
		if correctCount is wordCount then
			set btns to {"Cancel", continueBtn}
		else
			set btns to {"Cancel", "Show Errors", continueBtn}
		end if
		set Btn to button returned of (display dialog "Correct answers: " & (correctCount * 100 / wordCount + 0.5) ¬
			div 1 & "% (" & correctCount & " of " & wordCount & ")." buttons btns default button 2)
		if Btn is "Show Errors" then
			choose from list errorList with prompt "Original" & tab & tab & ¬
				"Entered" OK button name continueBtn with empty selection allowed
			if result is false then return
		end if
	end repeat
end play_game

setup_game()
play_game()

It gives me an error and highlights:

set w to some item of theList

Can you give me a hint as to what went wrong? I want to try and figure this out on my own, but I’d love a hint.