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