Apple is defining result as a variable

this is my script

set SnakeDrawing to "0)))))))))"

set AttackMessage to "You went to the snake with your brand new Iron Sword, As confident as a wolf you strike the snake and kill it ine one ****! proudly you open the chest and get another part of the map! you go through the door and find some food to eat, you rest for a minute or so and continue on your journey."

set SnakeMessage to "You reached to the snake location and find a pathway but you can't barehandedly attack those snakes, why dont you check the shack treasure chest."

set ShackMessage to "You enter the shack, there on the floor you find a chest. You open it and inside there was a Iron Sword [Automaticaly Equiped]"

set ExplanitoryMessage to "since you had a good look you probably want to know what the little markings mean right? If you do then let me tell you. - is a door, _ is nothing but land, * is a treasure, V is you and ~~ is a snake different enemies will appear across different map sections"

set MapForm1 to "XXXXXXXXXXXX

XV___________X                   

X_X---X___X~~X

X_X__X___X  - 

XXXXXXXXXXXX"

display dialog "You awaken from what seems to be a deep slumber, noticing you have forgotten all knowledge puts fear into your heart. You have found a map on your lap" buttons {"Open", "Throw it out"} default button 1

if the button returned of the result is "Open" then

display dialog MapForm1 buttons {"Had a good glance? You will have another chance to look again later."}

else

display dialog "This map pulses with energy, you couldn't convince yourself to throw it out so you opened it" buttons {"Continue"}

end if

if the button returned of the result is "Continue" then

display dialog MapForm1 buttons {"Had a good glance? You will have another chance to look again later."}

end if

display dialog ExplanitoryMessage buttons {"I understand so LETS EXPLORE!"}

display dialog "You have 2 areas to go to, either the snake or the shack, what do you pick?" buttons {"Shack", "Snake"}

if the button returned of the result is "Shack" then

display dialog ShackMessage buttons {"Awesome!"}

else

display dialog SnakeMessage buttons {"Continue to shack"}

end if

if the button returned of the result is "Continue to shack" then display dialog ShackMessage buttons {"Awesome!"}

if the button returned of the result is "Awesome!" then

display dialog AttackMessage buttons {"Great let’s continue!"}



display dialog "The snake was a beautiful creature so I drew it on your notebook, want to see?" buttons {"Ok why not?", "Later"}



if the button returned of the result is "Ok why not?" then

	display dialog SnakeDrawing buttons {"It's Beautiful!", "It looks terrible ;-;"}

	

	

	if the button returned of the result is "Later" then

		display dialog "Ok" buttons {"Continue"}

		

		if the button returned of the result is "It looks terrible ;-;" then

			display dialog "I'm starting to regret helping you out, please don't be mean" buttons {"Ok I won't be mean"}

			

		end if

		if the button returned of the result is "It's Beautiful!" then

			display dialog "Thanks! I worked really hard on it" buttons {"No problem!"}

			

			

		end if

	end if

end if

end if

display dialog "The End For Now" buttons {"Ok ;("}

By the way my variables are on the top the script is down under the variables

The result property contains the resulting value (if any) of the last statement executed. You are continually getting the button returned of the result, but result can change if you do something else from when it was last set, such as executing an if statement.  Best practice is to save result in a variable unless you plan on immediately using it.

In this case, when choosing to go to the shack, if the button is "Awesome!" then the next if statement sets result to undefined (since the statement doesn’t return anything), which then fails when you try to get its button returned again in the next if statement.  The solution would be to do something like:

# previous statements
display dialog "You have 2 areas to go to, either the snake or the shack, what do you pick?" buttons {"Shack", "Snake"}
if the button returned of the result is "Shack" then
	display dialog ShackMessage buttons {"Awesome!"}
else
	display dialog SnakeMessage buttons {"Continue to shack"}
end if
set snakeOrShack to button returned of the result -- save for the next couple of comparisons
if snakeOrShack is "Continue to shack" then display dialog ShackMessage buttons {"Awesome!"}
if snakeOrShack is "Awesome!" then
	# the rest
end if

If this is the start of something bigger, a better approach would be to create a data structure that contains all the dialogs and what to do with their result, and some handlers to use it, or it is going to get really difficult to keep track.

Thanks a lot!

Apple is defining result as a variable
 
 
Q