Reviving an old script I wrote, need help.

So, I wrote this silly little script that does a magic card trick way back in 2008.
Thought about it again today and decided to check it out.

but it is now broken.

Wondering if anyone can help me figure it out.

The issue, I think is in the “property colorList” section.
These used to be unicode symbols for Clubs, Hearts, Spades and Diamonds
But I assume that they don’t work anymore given the A with a carrot over them.

when I run it as is, I get a “Syntax error: Expected expression, etc. but found unknown token.”

I wouldn’t mind converting this to java or python or something that might run on a simple website for fun at some point, but obviously need to get it working again first.

Any help would be appreciated.
Thanks!
My original post: https://macscripter.net/viewtopic.php?id=25554

property cardList : {"King", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "--You cheated, it wasn't in all four!"}
property colorList : {«data utxt2665», «data utxt2666», «data utxt2660», «data utxt2663»}
property questionList : {"Is the rank of your card equal to any of these? 3, Jack, 5, Ace, 9, 7?", "Ok, how about these? 10, 3, 6, 2, 7, Jack?", "Almost done, how about these? 5, Queen, 6, 7, 4?", "Last round: Queen, 9, 8, Jack, 10"}

repeat
   display dialog "Think of any playing card in a normal deck...
And for the moment, just forget about the suit, and the color of your card. Only think of the number or letter."
   
   set theResult to 0
   repeat with i from 1 to 4
       set b to button returned of (display dialog item i of questionList buttons {"No", "Yes"})
       if b is "Yes" then set theResult to (theResult + (2 ^ (i - 1))) as integer
   end repeat
   try
       set theResult to item (theResult + 1) of cardList
       exit repeat
   on error
       display dialog "--You cheated, it wasn't in all four!" buttons {"Cancel", "Try Again"} default button 2
   end try
end repeat

--figure out the color
display dialog "Great, now I want you to remember the color of your card. Imagine it bright and vivid in your mind."
if button returned of result is "OK" then
   display dialog "Ok, I am getting something, does the word 'cherry' mean anything to you?" buttons ["Nope", "Yes, it does"]
   if button returned of result is "Yes, it does" then
       set theColor to 1 -- "red"
   else
       set theColor to 3 -- "black"
       display dialog "Oh.. well I meant 'Black Cherry', we'll move on."
   end if
end if
display dialog "Your card is a " & item theColor of colorList & " correct?" buttons ["No, its not", "Yes, it is"]
if button returned of result is "Yes, it is" then
   display dialog "I thought so, you're thinking of the " & theResult & " of " & item theColor of colorList buttons {"Have a great day!"} default button 1
else
   display dialog "Oh, well I sometimes have trouble with the " & theResult & " of " & item (theColor + 1) of colorList buttons {"Have a great day!"} default button 1
end if

Older version that still mostly works but fails if the selected card is a Club or Spade

display dialog "Think of any playing card in a normal deck...
And for the moment, just forget about the suit, and the color of your card. Only think of the number or letter."

property questionList : {"Is the rank of your card equal to any of these? 3, Jack, 5, Ace, 9, 7?", "Ok, how about these? 10, 3, 6, 2, 7, Jack?", "Almost done, how about these? 5, Queen, 6, 7, 4?", "Last round: Queen, 9, 8, Jack, 10"}

set theResult to 0
repeat with i from 1 to 4
   set b to button returned of (display dialog item i of questionList buttons {"No", "Yes"})
   if b is "Yes" then set theResult to (theResult + (2 ^ (i - 1))) as integer
end repeat

--figure out the color
set theColor to 0
display dialog "Great, now I want you to remember the color of your card. imagine it bright and vivid in your mind."
if button returned of result is "OK" then
   display dialog "Ok, I am getting something, does the word 'cherry' mean anything to you?" buttons ["Nope", "Yes, it does"]
   if button returned of result is "Yes, it does" then
       set theColor to "red"
   else
       set theColor to "black"
       display dialog "Oh.. well I meant 'Black Cherry', we'll move on."
   end if
   if theResult is 1 then set theResult to "Ace"
   if theResult is 2 then set theResult to "Two"
   if theResult is 3 then set theResult to "Three"
   if theResult is 4 then set theResult to "Four"
   if theResult is 5 then set theResult to "Five"
   if theResult is 6 then set theResult to "Six"
   if theResult is 7 then set theResult to "Seven"
   if theResult is 8 then set theResult to "Eight"
   if theResult is 9 then set theResult to "Nine"
   if theResult is 10 then set theResult to "Ten"
   if theResult is 11 then set theResult to "Jack"
   if theResult is 12 then set theResult to "Queen"
   if theResult is 0 then set theResult to "King"
   if theResult is 15 then set theResult to "--You cheated, it wasn't in all four!"
end if

if theColor is "red" then display dialog "Your card is a Heart correct?" buttons ["No, its not", "Yes, it is"]
if button returned of result is "Yes, it is" then
   display dialog "I thought so, you're thinking of the " & theResult & " of Hearts" buttons {"Have a great day!"} default button 1
else
   display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Diamonds" buttons {"Have a great day!"} default button 1
   
   if theColor is "black" then display dialog "Your card is a Spade correct?" buttons ["No, its not", "Yes, it is"]
   if button returned of result is "Yes, it is" then
       display dialog "I thought so, you're thinking of the " & theResult & " of Spades" buttons {"Have a great day!"} default button 1
   else
       display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Clubs" buttons {"Have a great day!"} default button 1
   end if
end if

I edited the second script and the following revision seems to work. The substantive change is to the last if statement.

display dialog "Think of any playing card in a normal deck...
And for the moment, just forget about the suit, and the color of your card. Only think of the number or letter."

set questionList to {"Is the rank of your card equal to any of these? 3, Jack, 5, Ace, 9, 7?", "Ok, how about these? 10, 3, 6, 2, 7, Jack?", "Almost done, how about these? 5, Queen, 6, 7, 4?", "Last round: Queen, 9, 8, Jack, 10"}

set theResult to 0
repeat with i from 1 to 4
	set b to button returned of (display dialog item i of questionList buttons {"No", "Yes"})
	if b is "Yes" then set theResult to (theResult + (2 ^ (i - 1))) as integer
end repeat

if theResult = 0 then
	set theResult to "King"
else if theResult = 15 then
	set theResult to "--You cheated, it wasn't in all four!"
else
	set theResult to item theResult of {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen"}
end if

--figure out the color
set theColor to 0
display dialog "Great, now I want you to remember the color of your card. imagine it bright and vivid in your mind."
if button returned of result is "OK" then
	display dialog "Ok, I am getting something, does the word 'cherry' mean anything to you?" buttons ["Nope", "Yes, it does"]
	if button returned of result is "Yes, it does" then
		set theColor to "red"
	else
		set theColor to "black"
		display dialog "Oh.. well I meant 'Black Cherry', we'll move on."
	end if
end if

if theColor is "red" then
	display dialog "Your card is a Heart correct?" buttons ["No, its not", "Yes, it is"]
	if button returned of result is "Yes, it is" then
		display dialog "I thought so, you're thinking of the " & theResult & " of Hearts" buttons {"Have a great day!"} default button 1
	else
		display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Diamonds" buttons {"Have a great day!"} default button 1
	end if
else if theColor is "black" then
	display dialog "Your card is a Spade correct?" buttons ["No, its not", "Yes, it is"]
	if button returned of result is "Yes, it is" then
		display dialog "I thought so, you're thinking of the " & theResult & " of Spades" buttons {"Have a great day!"} default button 1
	else
		display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Clubs" buttons {"Have a great day!"} default button 1
	end if
end if

There is a sticky post in this forum that has a script that lets you get the correctly encoded text. This is likely what the original text was:

[format]property colorList : {«data utxt2665», «data utxt2666», «data utxt2660», «data utxt2663»}[/format]

A simple way to get the characters:


character id {9829, 9830, 9827, 9824}
--> "♥♦♣♠"

And, to translate the other way:


id of "♥♦♣♠"
--> {9829, 9830, 9827, 9824}

This ia a very inefficient syntax. Imagine that theResult is 1 then all subsequent lines are a waste of time and resources.

A more efficient way is a list


set cards to {"King", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen"}
if theResult < 13 then
	set theResult to item (theResult + 1) of cards
else
	set theResult to "--You cheated, it wasn't in all four!"
end if

HAHA, Stefan, looks like you have said this to me before!

https://macscripter.net/viewtopic.php?id=25546

When I first made the script that was the suggestion you made.
The first script in my top post of this has your adaptation of the script. it was your idea to use the symbols in the first place.

Nice to see you are still active on this board.