Changing gender - how to do it elegantly?

Well, there IS that issue - I was gonna write a separate question. Assuming I use the Boolean option, and I wanted the stat screen to display “Man” or “Woman,” then how would I go about it?

If it’s impossible, then, I’d do it as a string and be done with it, as suggested earlier. Which seems easier to code, for me, at my current, ah, coding “level.”

@CJW It’s mostly for aesthetic purpose in my case. I figure if I could define the gender in only one place and throw them back as end-user info (mostly because how do you explain a boolean variable to the reader-player to understand that they are playing a male/female?), plus I like my linecount to be as anorexic as possible, it then eliminates the reason for further using a separate variable. But @StanTheMan, I’d look at the direction where I want to go with the setup. Boolean for gender is definitely nice and quick assuming you only deal with male-female context. I only go string for the display.

edit
Wait a sec… is it possible to retract values (“male”) from boolean and slap them onto the screen with the $! thing? You’re giving me ideas…

@FcA No… Haha.

It means if you write everything in lowercase in a variable, for e.g. *set name “alice”
And then you type ${name} - it’ll print “alice” - right?

But if you put an exclamation mark in front of it, it’ll capitalize the first letter, and print “Alice” $!{name}

Two exclamation marks capitalizes the whole word.

That I know. Been using them a little here and there for other purpose, I just thought… oh nevermind. Lol.

Anyway, just strikes me that a cute workaround may be doable.

Setup 1. Gender in string, display directly.

*set gender "male" and *set gender "female" where applicable, then in your stats txt, ${gender} or, yes, $!{gender} if feeling like it.

Setup 2. Gender in boolean, display with a condition check.

*set male true and *set male false where applicable, then in the stats txt,


*if (male)
  Male
*if !(male)
  Female

@CJW A few days late, but reading a post about gender, I can’t help but laugh when variable I see listed is blue_ball. I can’t be the only person childish enough to have started laughing from seeing that.

@StanTheMan As FcA mentioned, it can be done with variables. Another thing you can do (if you prefer to avoid the confusion of using 'not equal to’s) is to have two variables: male and female (and possibly a third non_gendered if you want to give the option), so that rather than:


*if male
  Male
*if (male = false)
  Female

You’ll end up using the more natural:


*if male
  Male
*if female
  Female

BTW, as an alternative to


if (male=false)
  Female stuff

there is always:


if not(male)
  Female stuff

This way readability is improved while maintaining the improved efficiency of a single boolean variable.

The bigger your game gets, the more important it becomes to keep your code as efficient as possible to reduce the number of bugs you have to find and fix. Every new variable you create is one more that you’ll have to properly initialize and maintain. Every new variable you create is also one more potential source of bugs. In this particular case you may end up with weird situations like (male=true and female=true), or (male=false and female=false) that are completely impossible when you use a single boolean variable.

This is just a small hassle when we’re dealing with variables that are static (stay the same) through the entirety of the game, like gender, but it can turn into a —huge headache— when the variable values can change during the game. It’s thus best to learn good coding habits and stick to them, even for the small stuff. You’ll thank yourself later as your game nears completion.

The single boolean variable does not need to be ‘male’ of course. It could just as easily be ‘female’. I’d only recommend the two variable scenario for gender for those who specifically desire to allow for transgendered protagonists.