Help with "if..."

Foxxpaw
05 Jul 2016, 12:00

Okay, so I'm probably doing this horribly wrong, but here's the issue. I am trying to setup the option for a player to create a character with a custom name and gender. To do that, I set up a few functions which I then nested in the "game setup" function. The startup script is one line: gameSetup.


--------------------------------

function gameSetup
msg (""Greetings! Welcome to the city of Silverwood. You must be new here. What's your name?"")
if (game.nameSetup = "True") {
genderSetup
}
else {
nameSetup
}

--------------------------------

function nameSetup
set (player, "alias", result)
Ask (""So your name is " + player.alias + "?"") {
if (result) {
game.nameSetup = "True"
}
else {
msg (""Oh, sorry. What is your name again?"")
nameSetup
}
}

--------------------------------

function genderSetup
ShowMenu ("And what is your gender?", Split ("Male;Female", ";"), false) {
player.gender = result
Ask (""So you are a " + player.gender + "?"") {
if (result) {
msg ("Okay! Lets get you situated. I'll show you to your apartment!")
game.genderSetup = "True"
}
else {
genderSetup
}
}
}

--------------------------------

So here's where I'm confused. I'm not certain on how I can constantly check for the completion of the nameSetup attribute. As far as I am aware, if... only checks it when it is run. I'm sure I'm missing something really obvious. lol.


Jay Nabonne
05 Jul 2016, 12:19

gameSetup is only called once, and nameSetup will never be true at that point (note that you can use boolean true and false instead of string "True" if you wish).

What I think you want is that gameSetup calls nameSetup. Then in the "if" part of nameSetup, instead of setting game.nameSetup to true, just call on to genderSetup. It will be a single chain through the code. You don't need the variables at all.

gameSetup calls nameSetup which calls genderSetup.


Foxxpaw
05 Jul 2016, 13:14

Ah...Yeah, that seems to work a lot better. Modified it a little and added in a confirmation function.

Dang it this is why I shouldn't be allowed near code when I'm tired ^^; haha. Thanks a ton :)


hegemonkhan
05 Jul 2016, 18:58

there's also these to look at too:

http://docs.textadventures.co.uk/quest/guides/
http://docs.textadventures.co.uk/quest/guides/character_creation.html

http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game