What about adding an " to a string?

I know I’ve been posting a lot recently but thats what MacScripter is for.

How do you put an " in a string or whatever.


set player_name to """ & "Timothy" & """

It dosen’t work.

You need to escape certain characters, such as quotation marks, Fistoprince:

set player_name to "\"" & "Timothy" & "\""
--> "\"Timothy\""

While the result may not be what you expected, you’re just seeing how AppleScript handles such matters. If you then do something with the text (such as put it into a text document, or use it in a dialog) then you’ll get what you’re after:

set player_name to "\"Timothy\""
display dialog player_name

Oh, Thanks! It’s exactly what I needed. The final script looks like this for all thoes interested:


tell application "Script Editor"
	tell (make new document)
		set its text to "--Saved game for Hassumi
set player_name to " & "\"Timothy\"" & "
set player_type to {" & "\"Destruction\"" & "}
set player_intelligence to 1
set player_ST.ability to 1
set player_DE.ability to 1
set player_WI.ability to 1
set player_LI.ability to 1
set player_DA.ability to 1
set player_HI.ability to 1
set player_WA.ability to 1
set player_FI.ability to 1
set player_money to 100"
		save in file ("Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games" & "Timothy.sav")
	end tell
	close window 1
end tell

It’s a save game script.

One more small problem… It won’t save, I need to take a screenshot to read the error message because it dosn’t stay up long enough (It say syntax error An unknown token can’t go after this identifyer “”".) It seems to be ignoring the ''
and, how do I make the program read it afterwards?

i just loaded your script and it seems that it doesn’t like the period in the variable name.

Heh, I only just realised that now. I replaced it with _ and it works just fine. Thanks anyhow.

But still, how do I read scripts?

You use the ˜load script’ command (found in the StandardAdditions dictionary).

set whatever to load script someAlias

However, your current script won’t work very well for what you’re trying to do. All that the ˜whatever’ script object will be able to do is run; This will just set a bunch of variables that are local to the object, all of which will be forgotten after the run is complete. To be able to store and access variables in a script object, you’ll need to use properties instead.

I would consider including something like this inside your script:

script PlayerSaveTemplate
	property player_name : missing value
	property type : missing value
	property intelligence : missing value
	property ST_ability : missing value
	property DE_ability : missing value
	property WI_ability : missing value
	property LI_ability : missing value
	property DA_ability : missing value
	property HI_ability : missing value
	property WA_ability : missing value
	property FI_ability : missing value
	property money : missing value
end script

To save it, you could use something like this:

copy PlayerSaveTemplate to PlayerSave

tell PlayerSave
	set player_name to "Timothy"
	set type to {"Destruction"}
	set intelligence to 1
	set ST_ability to 1
	set DE_ability to 1
	set WI_ability to 1
	set LI_ability to 1
	set DA_ability to 1
	set HI_ability to 1
	set WA_ability to 1
	set FI_ability to 1
	set money to 100
end tell

store script PlayerSave in file ("Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games" & "Timothy.sav") replacing yes

No dice. Dosen’t get the message. I don’t think I quite understand anyway. here’s what I tried:


--**********************here***********************
script PlayerSaveTemplate
	property player_name : missing value
	property type : missing value
	property intelligence : missing value
	property ST_ability : missing value
	property DE_ability : missing value
	property WI_ability : missing value
	property LI_ability : missing value
	property DA_ability : missing value
	property HI_ability : missing value
	property WA_ability : missing value
	property FI_ability : missing value
	property money : missing value
end script
display dialog "Welcome to the land of Hassumi." & return & "In this land you will find out about the 5 gems of power." buttons {"OK"}
set button to the button returned of (display dialog "Please, stranger, What will you do?" buttons {"Load Game", "New Game"} default button {"New Game"})
if button is "New Game" then
	set player_name to the text returned of (display dialog "Please tell us your name:" default answer "" buttons {"Thats me!"})
	set types to {"Stealth", "Destruction", "Wisdom", "Light", "Darkness", "Hidden Identity", "Water", "Fire"}
	set player_type to (choose from list types with prompt "What type of person are you?" cancel button name "")
	display dialog "Welcome to Hassumi, " & player_name & " the " & player_type & " specialist."
	copy PlayerSaveTemplate to PlayerSave
	--**********************here***********************
	tell PlayerSave
		set player_name to player_name
		set type to {player_type}
		set intelligence to 1
		set ST_ability to 1
		set DE_ability to 1
		set WI_ability to 1
		set LI_ability to 1
		set DA_ability to 1
		set HI_ability to 1
		set WA_ability to 1
		set FI_ability to 1
		set money to 100
	end tell
	store script PlayerSave in file ("Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:" & player_name) replacing yes
else if button is "Load Game" then
	set saved_games to list folder "Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:"
	choose from list saved_games
	set player_name to the result
	load script "Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:" & player_name
	display dialog player_intelligence
end if

Maybe this will help:

display dialog "Welcome to the land of Hassumi." & return & "In this land you will find out about the 5 gems of power." buttons {"OK"}
display dialog "Please, stranger, What will you do?" buttons {"Load Game", "New Game"} default button {"New Game"}
get button returned of result

if result is "New Game" then
	copy playerTemplate to player
	
	display dialog "Please tell us your name:" default answer "" buttons {"Thats me!"}
	set player's name to text returned of result
	
	set types to {"Stealth", "Destruction", "Wisdom", "Light", "Darkness", "Hidden Identity", "Water", "Fire"}
	set player's type to (choose from list types with prompt "What type of person are you?" cancel button name "")
	
	display dialog "Welcome to Hassumi, " & player's name & " the " & player's type & " specialist."
	
	tell player
		set it's intelligence to 1
		set it's ST_ability to 1
		set it's DE_ability to 1
		set it's WI_ability to 1
		set it's LI_ability to 1
		set it's DA_ability to 1
		set it's HI_ability to 1
		set it's WA_ability to 1
		set it's FI_ability to 1
		set it's money to 100
	end tell
	
	store script player in file ("Mac mini HD:Users:bruce:Desktop:" & player's name) replacing yes
else if result is "Load Game" then
	list folder "Mac mini HD:Users:bruce:Desktop:" without invisibles
	choose from list result
	
	set player to load script alias ("Mac mini HD:Users:bruce:Desktop:" & first item of result)
	
	display dialog (player's intelligence as text)
end if


script playerTemplate
	property name : missing value
	property type : missing value
	property intelligence : missing value
	property ST_ability : missing value
	property DE_ability : missing value
	property WI_ability : missing value
	property LI_ability : missing value
	property DA_ability : missing value
	property HI_ability : missing value
	property WA_ability : missing value
	property FI_ability : missing value
	property money : missing value
end script

on the


set player to load script "Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:" & first item of result

it says :Can’t make
Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:""into type file

My fault, replace it with something like this:

set player to load script alias ("Gentfamdisc:Users:Tim:Desktop:Hassumi:Saved Games:" & first item of result)

(I’ve edited the script above to use this.)

Seems to work, uuh, why does intelligence return “msng”?

Sorry, you need to change the ˜new game’ part:

	tell player
		set it's intelligence to 1
		set it's ST_ability to 1
		set it's DE_ability to 1
		set it's WI_ability to 1
		set it's LI_ability to 1
		set it's DA_ability to 1
		set it's HI_ability to 1
		set it's WA_ability to 1
		set it's FI_ability to 1
		set it's money to 100
	end tell

(Again, I’ve edited the earlier to use this.)

Thanks, works fine now! But what part of that is the ‘save game’ bit?:confused: