Guessing game problem

run that, if you start by guessing a single digit 8 and your second guess is double digit 13 then it brings up this thing that says the variable result is not defined, and result is not a variable. it does the same thing if you start with a two digit number that ends with 0 and your second guess is a double digit that ends in a non zero number then it does the same thing. why???

set start to {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”, “13”, “14”, “15”, “16”, “17”, “18”, “19”, “20”, “21”, “22”, “23”, “24”, “25”, “26”, “27”, “28”, “29”, “30”, “31”, “32”, “33”, “34”, “35”, “36”, “37”, “38”, “39”, “40”, “41”, “42”, “43”, “44”, “45”, “46”, “47”, “48”, “49”, “50”, “51”, “52”, “53”, “54”, “55”, “56”, “57”, “58”, “59”, “60”, “61”, “62”, “63”, “64”, “65”, “66”, “67”, “68”, “69”, “70”, “71”, “72”, “73”, “74”, “75”, “76”, “77”, “78”, “79”, “80”, “81”, “82”, “83”, “84”, “85”, “86”, “78”, “88”, “89”, “90”, “91”, “92”, “93”, “94”, “95”, “96”, “97”, “98”, “99”, “100”}
set guess to (item (random number from 1 to (length of start)) of start)
set finaly to (guess) as integer
display dialog “guess what number i picked (1-100)” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “to High, guess again” default answer “”
if guessed is less than finaly then display dialog “to low, guess again” default answer “”
set guessed to the text returned of the result as integer
if guessed is equal to finaly then display dialog “You win!”
end
if guessed is greater than finaly then display dialog “Aww too bad your last guess was too high my number was (finaly).”
if guessed is less than finaly then display dialog “Aww too bad that your last guess was too low, my number was (finaly).”

There are a lot of things wrong with your script. Among other things, you define several things that you don’t need to; you don’t use compound if-then statements; you don’t use repeat loops; you don’t test to make sure the user entered an integer, and you are misusing the end command (you want to use return). Here is a much simplified script that does what I think you want it to do. It will randomly choose a number from 1 to 100. It will then give you 5 chances to guess correctly, telling you if each guess is too high or too low. If you don’t guess correctly in your 5 tries, it will tell you what the number was. If you do guess correctly, the script will end:

set {the_message, low_num, high_num} to {"", 1, 100}
set finaly to (random number from low_num to high_num)
repeat with i from 1 to 5
	if the_message is not "" then set the_message to ("" & guessed & " was too " & the_message & ", try again." & return & return)
	repeat
		try
			set guessed to text returned of (display dialog "Guess " & i & return & return & the_message & "Guess what number I picked (" & low_num & "-" & high_num & "):" default answer "") as integer
			exit repeat
		on error
			if the_message does not start with "T" then set the_message to "That was not an integer." & return & return & the_message
		end try
	end repeat
	if guessed = finaly then
		display dialog "You win!"
		return
	else if guessed > finaly then
		set the_message to "high"
	else if guessed < finaly then
		set the_message to "low"
	end if
end repeat
display dialog "Aww too bad that your last guess was too " & the_message & ", my number was " & finaly & "."

Jon

i just learned applescript so i didnt know half the stuff you said means, what does return do what how do you use repeat and what does try do?

See if this (less efficient) script is easier to read and decipher:

-->Define myAnswer as a Random Number from 1 to 100
set myAnswer to ((random number) * 100) as integer
set numGuesses to 0
set yourGuess to ""
set winFlag to "N"

display dialog myAnswer

repeat with guessCount from 1 to 7
	if winFlag = "N" then
		display dialog (guessCount as string) & ":  Guess what number I picked (from 1-100)" default answer ""
		set yourGuess to the text returned of the result as integer
		
		if yourGuess = myAnswer then
			display dialog "You Win!"
			set numGuesses to guessCount
			set winFlag to "Y"
		else
			if yourGuess > myAnswer then
				display dialog "Too High.  Guess Again."
			else
				display dialog "Too Low.  Guess Again."
			end if
		end if
	end if
	
end repeat

if yourGuess = myAnswer then
	--> If they had won... Do whatever
	display dialog "Congratulations, you had guessed my answer of " & (myAnswer as text) & " in " & (numGuesses as text) & " guesses."
else
	if yourGuess > myAnswer then
		display dialog "Your last guess was too High.  My answer was " & (myAnswer as text) & "."
	else
		display dialog "Your last guess was too Low.  My answer was " & (myAnswer as text) & "."
	end if
	
end if