coercion error

i have a script that includes a dialog box to write in a number. To make the script more user-friendly, I have it writing a file when you enter a number and then it reads from this when next creating the dialog box and makes the default answer the last number you wrote in. The problem is that, if I don’t rewrite the number in the dialog box, it can’t coerce the default answer into a number, even though it is a number. This seems to be a problem with reading from the file, because when I then retype the number (exactly the same way), it is able to coerce it. What gives?


display dialog is working only with text, not with numbers.
So you have to coerce the number to a string before passing it to display dialog.
Here a (silly) example

set t to 1
	set n to text returned of (display dialog "Enter a number" default answer t as string)
		set t to (n as integer) + 1
	on error
		exit repeat
	end try
end repeat