Chapter 5: Strings, Lists, & Records (Code Check)

This is from the chapter 5 exercise in AppleScript Programming for the absolute beginner.
The main error I get is “Expected “timeout” or “transaction” but found identifier. - 2,741” Should I remove the paragraph breaks? Not sure how to fix this.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- 
-- Script Name: Godfather Trivia Quiz Game.scpt
-- Version: 1.0
-- Author: Jerry Lee Ford, Jr.
-- Date: August 2007
--
-- Desciption: This AppleScript tests the player's knowledge of the
-- Godfather movie by presenting a list of multiple-choice questions
-- and challenges the player to select the correct answers.
--

-- Define and initialize variable values
set NoCorrect to 0 -- Keeps a count of correctly answered questions
set GameTitle to "Godfather Trivia Quiz" -- Store's the game's name

-- Present the first question
set Q1 to choose from list {"Santino Corleone", "Fredo Corleone", "Connie Corleone", "Tom Hagen"}¬
with prompt "What was the name of the Godfather's oldest child?"¬
with title GameTitle

-- Present the second question
set Q2 to choose from list {"Michael Corleone", "Don Vito Corleone", "Luca Brasi", "Bruno Tattaglia"}¬
with prompt "Who ended up sleeping with the fishes?"¬
with title GameTitle

-- Present the third question
set Q3 to choose from list {"Johnny Fontane", "Moe Greene", "Amerigo Bonasera", "Pete Clemenza"}¬
with prompt "Upon whose service did the Godfather call when " & "his son was killed?"¬
with title GameTitle

-- Present the fourth question
set Q4 to choose from list {"Causeway Tollboth", "Vegetable Market", "Connie's Apartment", "Tessio's Territory"}¬
with prompt "Where was Solenzio killed?"¬
with title GameTitle

-- Present the fifth question
set Q5 to choose from list {"Italy", "Sardinia", "Sicily", "England"}¬
with prompt "To what country was Michael sent are killing the " & "Turk?"¬
with title GameTitle

-- Present the sixth question
set Q6 to choose from list {"Tom Hagen", "Luca Brasi", "Salvatore Terrio", "Pete Clemenza"}¬
with prompt "Who was Don Corleone's consigleri?"¬
with title GameTitle

-- Present the seventh question
set Q7 to choose from list {"Grocery", "Flea Market", "Olive Oil", "Music Store"}
with prompt "What kind of business did the Godfather operate?"¬
with title GameTitle

-- Present the eighth question
set Q8 to choose from list {"A Request", "A Loan", "A Dance", "A Hug"}¬
with prompt "What can't a Sicilian refuse on his daughter's " & "wedding day?"¬
with title GameTitle

-- Present the ninth question
set Q9 to choose from list {"Luca Brasi", "Kay Adams", "Don Vito Corleone", "Pete Clemensa"}¬
with prompt "Who taught Michael how to cook?"¬
with title GameTitle

-- Present the tenth question
set Q10 to choose from list {"Cat", "Dog", "Bird", "Fish"}¬
with prompt "What type of pet did the Godfather have?"¬
with title GameTitle

-- Analyze the player's answers and tally the number of correct answers
if Q1 = {"Fredo Corleone"} then set NoCorrect to NoCorrect + 1
if Q2 = {"Luca Brasi"} then set NoCorrect to NoCorrect + 1
if Q3 = {"Amerigo Bonasera"} then set NoCorrect to NoCorrect + 1
if Q4 = {"Causeway Tollboth"} then set NoCorrect to NoCorrect + 1
if Q5 = {"Sicily"} then set NoCorrect to NoCorrect + 1
if Q6 = {"Tom Hagen"} then set NoCorrect to NoCorrect + 1
if Q7 = {"Olive Oil"} then set NoCorrect to NoCorrect + 1
if Q8 = {"A Request"} then set NoCorrect to NoCorrect + 1
if Q9 = {"Pete Clemensa"} then set NoCorrect to NoCorrect + 1
if Q10 = {"Cat"} then set NoCorrect to NoCorrect + 1

-- Determine whether or not the player passed and what ranking,
-- if applicable, should be assigned
if NoCorrect < 7 then¬
	display dialog "You have failed. Study hard and try again later." buttons {"OK"}
else if NoCorrect = 7 then¬
	display dialog "You have passed with a ranking of Button Man!" buttons {"OK"}
else if NoCorrect = 8 then¬
	display dialog "You have passed with a ranking of Capo!" buttons {"OK"}
else if NoCorrect = 9 then¬
	display dialog "You have passed with a ranking of Consigleri!" buttons {"OK"}
else if NoCorrect = 10 then¬
	display dialog "You have passed with a ranking of Godfather!" buttons {"OK"}
end if

Hi.

There’s a line-continuation character (¬) missing from the end of the line above where the error appears. There are also a few later on where there shouldn’t be any. I think this version’s OK, although the two ‘use’ lines at the top aren’t necessary:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- 
-- Script Name: Godfather Trivia Quiz Game.scpt
-- Version: 1.0
-- Author: Jerry Lee Ford, Jr.
-- Date: August 2007
--
-- Desciption: This AppleScript tests the player's knowledge of the
-- Godfather movie by presenting a list of multiple-choice questions
-- and challenges the player to select the correct answers.
--

-- Define and initialize variable values
set NoCorrect to 0 -- Keeps a count of correctly answered questions
set GameTitle to "Godfather Trivia Quiz" -- Store's the game's name

-- Present the first question
set Q1 to choose from list {"Santino Corleone", "Fredo Corleone", "Connie Corleone", "Tom Hagen"} ¬
	with prompt ¬
	"What was the name of the Godfather's oldest child?" with title GameTitle

-- Present the second question
set Q2 to choose from list {"Michael Corleone", "Don Vito Corleone", "Luca Brasi", "Bruno Tattaglia"} ¬
	with prompt ¬
	"Who ended up sleeping with the fishes?" with title GameTitle

-- Present the third question
set Q3 to choose from list {"Johnny Fontane", "Moe Greene", "Amerigo Bonasera", "Pete Clemenza"} ¬
	with prompt "Upon whose service did the Godfather call when " & ¬
	"his son was killed?" with title GameTitle

-- Present the fourth question
set Q4 to choose from list {"Causeway Tollboth", "Vegetable Market", "Connie's Apartment", "Tessio's Territory"} ¬
	with prompt ¬
	"Where was Solenzio killed?" with title GameTitle

-- Present the fifth question
set Q5 to choose from list {"Italy", "Sardinia", "Sicily", "England"} ¬
	with prompt "To what country was Michael sent are killing the " & ¬
	"Turk?" with title GameTitle

-- Present the sixth question
set Q6 to choose from list {"Tom Hagen", "Luca Brasi", "Salvatore Terrio", "Pete Clemenza"} ¬
	with prompt ¬
	"Who was Don Corleone's consigleri?" with title GameTitle

-- Present the seventh question
set Q7 to choose from list {"Grocery", "Flea Market", "Olive Oil", "Music Store"} ¬
	with prompt ¬
	"What kind of business did the Godfather operate?" with title GameTitle

-- Present the eighth question
set Q8 to choose from list {"A Request", "A Loan", "A Dance", "A Hug"} ¬
	with prompt "What can't a Sicilian refuse on his daughter's " & ¬
	"wedding day?" with title GameTitle

-- Present the ninth question
set Q9 to choose from list {"Luca Brasi", "Kay Adams", "Don Vito Corleone", "Pete Clemensa"} ¬
	with prompt ¬
	"Who taught Michael how to cook?" with title GameTitle

-- Present the tenth question
set Q10 to choose from list {"Cat", "Dog", "Bird", "Fish"} ¬
	with prompt ¬
	"What type of pet did the Godfather have?" with title GameTitle

-- Analyze the player's answers and tally the number of correct answers
if Q1 = {"Fredo Corleone"} then set NoCorrect to NoCorrect + 1
if Q2 = {"Luca Brasi"} then set NoCorrect to NoCorrect + 1
if Q3 = {"Amerigo Bonasera"} then set NoCorrect to NoCorrect + 1
if Q4 = {"Causeway Tollboth"} then set NoCorrect to NoCorrect + 1
if Q5 = {"Sicily"} then set NoCorrect to NoCorrect + 1
if Q6 = {"Tom Hagen"} then set NoCorrect to NoCorrect + 1
if Q7 = {"Olive Oil"} then set NoCorrect to NoCorrect + 1
if Q8 = {"A Request"} then set NoCorrect to NoCorrect + 1
if Q9 = {"Pete Clemensa"} then set NoCorrect to NoCorrect + 1
if Q10 = {"Cat"} then set NoCorrect to NoCorrect + 1

-- Determine whether or not the player passed and what ranking,
-- if applicable, should be assigned
if NoCorrect < 7 then
	display dialog "You have failed. Study hard and try again later." buttons {"OK"}
else if NoCorrect = 7 then
	display dialog "You have passed with a ranking of Button Man!" buttons {"OK"}
else if NoCorrect = 8 then
	display dialog "You have passed with a ranking of Capo!" buttons {"OK"}
else if NoCorrect = 9 then
	display dialog "You have passed with a ranking of Consigleri!" buttons {"OK"}
else if NoCorrect = 10 then
	display dialog "You have passed with a ranking of Godfather!" buttons {"OK"}
end if

Thanks Nigel for your input with this code check. How do you determine when a paragraph break is not necessary or needs to be added? That part of code writing, unlike determining logical scripts elsewhere, isn’t sinking in for me. @NigelGarvey

Hi Jonathan.

AppleScript’s line-continuation character (¬) allows a single instruction (usually a long one) to be split over more than one line for clarity. For example, this in your code …

set Q1 to choose from list {"Santino Corleone", "Fredo Corleone", "Connie Corleone", "Tom Hagen"} ¬
	with prompt ¬
	"What was the name of the Godfather's oldest child?" with title GameTitle

… is actually the single instruction …

set Q1 to choose from list {"Santino Corleone", "Fredo Corleone", "Connie Corleone", "Tom Hagen"} with prompt "What was the name of the Godfather's oldest child?" with title GameTitle

… whose parts the author has split over three lines to make the code easier to read. It makes no difference to the way the code works as long as the line-continuation characters are there to indicate both to the reader and to the mechanism compiling the script that the three lines are really one.

@NigelGarvey Thanks for the clarification on this. That helps. Then the errors I am getting are likely not related to the paragraph breaks I currently use. So I need to solve those errors I am getting based on what I am learning in prior chapters for the book I am reading and applying.

There’s also a weird behavior with the complier in handling continuations in a line that ends with quoted text.

this uncompiled text:

set Q10 to choose from list {"Cat", "Dog", "Bird", "Fish"} ¬
	with prompt  "What type of pet did the Godfather have?"¬
	 with title GameTitle

Compiles like this:

set Q10 to choose from list {"Cat", "Dog", "Bird", "Fish"} ¬
	with prompt ¬
	"What type of pet did the Godfather have?" with title GameTitle

But, if you surround the quoted text with parens, it displays as you would expect:

set Q10 to choose from list {"Cat", "Dog", "Bird", "Fish"} ¬
	with prompt ("What type of pet did the Godfather have?") ¬
	with title GameTitle

@estockly Didn’t expect that. To me it doesn’t matter. As long as it successfully compiles without errors that is all I care about.

Edit: …and performs correctly.