The Result is Not Being Stored
jmnevil54
20 Jan 2021, 02:45I decided to have a break with the big coding stuff by trying my hand at a gamebook. But the result is not getting stored as the player.alias.
This is my code.
msg ("Cool!<br/><br/>(I can't program a game right...)<br/><br/>What's your name?<br/>")
options = Split("Crystal;Gold;Red;Green;Blue", ";")
ShowMenu ("What is your name?", options, false) {
switch (result) {
case ("Crystal") {
player.alias = result
msg ("You are Crystal.")
MovePlayer (Page3)
}
case ("Gold") {
player.alias = result
msg ("You are Gold.")
MovePlayer (Page3)
}
case ("Red") {
player.alias = result
msg ("You are Red.")
MovePlayer (Page3)
}
case ("Green") {
player.alias = result
msg ("You are Green.")
MovePlayer (Page3)
}
case ("Blue") {
player.alias = result
msg ("You are Blue.")
MovePlayer (Page3)
}
}
}
mrangel
20 Jan 2021, 09:19That should work (assuming the ShowMenu function is there, which I think it wasn't in the gamebook library under 5.7).
Could the problem be in the code you're using to display the alias?
However, your code is rather inefficient. Why have you got a switch block that does the same for every option? You could use something like:
options = Split("Crystal;Gold;Red;Green;Blue")
ShowMenu ("What is your name?", options, false) {
player.alias = result
msg ("You are " + result + ".")
MovePlayer (Page3)
}
jmnevil54
20 Jan 2021, 18:29Oh. Okay. Thanks.