For an import/export function in my program, I export a list such as {“Hello”, {“Hi”,“Bye”}} as the string "{"Hello",{"Hi", "Bye"}}, which appears to the user as {“Hello”, {“Hi”,“Bye”}}
Could someone PLEASE make a function to convert the string to the list? I’ve tried using textitem delimiters but it doesn’t seem to work.
Thanks so much.
CODE FOR SCRIPT:
property quizList : {}
to getNextToLast(array)
return last item of (reverse of (rest of (reverse of array)))
end getNextToLast
to makeListToString(array)
set finalString to ""
repeat with i from 1 to (count of array) - 2
set finalString to finalString & item i of array & ", "
end repeat
set finalString to finalString & (getNextToLast(array)) & " and " & last item of array
return finalString
end makeListToString
to getText(prompt)
display dialog prompt with title "iQuizU" buttons {"Quit", "OK"} cancel button "Quit" default button "OK" default answer ""
return text returned of result
end getText
to showAlert(displayText)
display dialog displayText with title "iQuizU" buttons {"Quit", "OK"} cancel button "Quit" default button "OK"
end showAlert
to showQuestion(prompt, qNum)
display dialog "Question #" & qNum & ": " & prompt default answer "" with title "iQuizU" buttons {"Quit", "Check Answer"} cancel button "Quit" default button "Check Answer"
return text returned of result
end showQuestion
to getNewQuestion()
return {getText("Enter the prompt for your new question."), getText("What would be the answer to that question?")}
end getNewQuestion
to makeNewQuiz()
set numQuestions to (getText("How many questions do you want this quiz to have?"))
repeat
try
set numQuestions to numQuestions as integer
exit repeat
on error
set numQuestions to (getText("Please enter an integer (e.g.: 3). How many questions do you want this quiz to have?"))
end try
end repeat
set questionList to {}
repeat numQuestions times
set end of questionList to (getNewQuestion())
end repeat
return {getText("Finally, enter a name for this quiz:"), questionList}
end makeNewQuiz
to askQuestion(questionData, questionNumber)
set questionResult to (showQuestion(item 1 of questionData, questionNumber))
return (questionResult = item 2 of questionData)
end askQuestion
to askQuiz(quizData)
showAlert("We're about to begin quiz \"" & item 1 of quizData & ".\" Press OK when you are ready to begin, or quit if you'd like to exit.")
set quizQuestions to item 2 of quizData
set wrongAnswers to {}
repeat with i from 1 to count of quizQuestions
set answeredCorrectly to (askQuestion(item i of quizQuestions, i))
if not answeredCorrectly then set end of wrongAnswers to i
end repeat
if length of wrongAnswers = 0 then
showAlert("Wow! You aced the quiz! Very nice work. Grade: 100%.")
else if length of wrongAnswers = 1 then
showAlert("You got question " & item 1 of wrongAnswers & " wrong, but, overall, nice job. Your grade: " & ((length of quizQuestions) - (length of wrongAnswers)) / (length of quizQuestions) * 100 & "%.")
else
showAlert("OK, you finished the quiz - you got questions " & makeListToString(wrongAnswers) & " wrong. Your grade: " & ((length of quizQuestions) - (length of wrongAnswers)) / (length of quizQuestions) * 100 & "%.")
end if
end askQuiz
// example quiz below
askQuiz({"Roots Test", {{"spect", "to watch"}, {"audi", "to listen"}, {"phon", "sound"}, {"vis", "to see"}, {"voc", "voice"}, {"dict", "to speak"}, {"scrib", "to write"}, {"scrip", "to write"}, {"graph", "to write, to record"}, {"soci", "community"}, {"mem", "to remember"}, {"de-", "down"}, {"port", "to carry"}, {"mis", "to send"}, {"mit", "to send"}, {"contra", "against"}, {"man", "hands"}, {"sol/solv", "to loosen"}, {"poli", "city"}, {"gen", "birth"}, {"nat", "born"}, {"spir", "to breathe"}, {"photo", "light"}, {"flam", "fire"}, {"-able", "adjective"}, {"-ize", "verb"}, {"per", "through"}, {"fero, ferre, tuli, latum", "to bring, to bear, to carry"}, {"tendo, tendare, tetendi, tensum", "to stretch"}, {"sub", "under"}, {"torqueo, torquere, torsi, tortum", "to twist"}, {"verso, versare, versavi, versatum", "to turn"}, {"ex", "from"}, {"pono, ponere, poosui, positum", "to put"}, {"extra", "on the outside"}, {"medius", "middle"}, {"sequor", "to follow"}, {"cum", "with"}, {"teneo, tenere, tenui, tentum", "to hold"}}})