Failed to declare variable

Foxxpaw
10 Oct 2022, 15:55So trying to figure out where I'm going wrong here.
I've declared the variable "temp" to contain the result from the user input. However, when it hits the else statement here, it breaks.
Error running script: Error compiling expression 'temp': Unknown object or variable 'temp'
msg ("What is your name?")
get input {
temp = CapFirst(result)
Ask ("So your name is "+temp+"?") {
if (result = false) {
getPlayerName
}
else {
player.alias = temp
msg ("Hello, " + player.alias)
}
}
}
mrangel
10 Oct 2022, 17:07Local variables only exist until the end of the script they are defined in.
The Ask
function displays a menu on the screen, and makes a note of a script to run when the player clicks on one of them. The stuff inside the Ask block is saved to a script attribute to run next turn, by which time your local variable has gone away.
You probably want to use something like game.temp
(or a more descriptive name), which is owned by an object (game
in this case), and continues to exist as long as that object does.

Foxxpaw
10 Oct 2022, 18:33Ah, okay. I'll keep that in mind going forward. Thanks! :D