True/False vs 0/1

No error, yet. But I’m not sure if it could cause one down the line.

I’ve been using numerical variables that initially start at 0 (false) and are updated later through play to 1 (true) which I believe is binary (I think).

Is there any disadvantage to this? I’m not sure if it could cause an issue or not, which is why I’d like to be informed before I continue writing and get in too deep.

I don’t see why it would, as long as you remember to treat them as 0 and 1 instead of false and true in the code.

1 Like

I don’t see a reason why it wouldn’t either, but then again I rarely see the reasons why my code stops working. xD

The first and last thing I’d say to anyone picking up CS is do what works for you. :slight_smile: This is a coding language originally designed to be used as widely as possible, by authors at all ranges of coding skill, not one designed to be as efficient or elegant as possible. The time you spend pushing out of your coding comfort zone to learn new things can be worthwhile, or it can just be time not spent finishing your actual game, slowing down your writing significantly as you try to incorporate things you’re not comfortable with. (Or even worse, spending time going back over existing working code and condensing it into a more efficient or elegant form. I promise you, it’s WAY more important to finish your game than to satisfy the aesthetic preferences of other hypothetical code-readers.)

With that said, if you’ve got a variable that you know will only be able to be set as true or false, there are a couple of minor reasons you might want to create it as a Boolean rather than numeric.

First, you can take advantage of the simplicity of Booleans to save a bit of typing. Instead of:

*if met_jones = 1
  "Hello again, Jones," you call.
*if met_jones = 0
  You introduce yourself to Jones for the first time.

you could have:

*if met_jones
  "Hello again, Jones," you call.
*if not(met_jones)
  You introduce yourself to Jones for the first time.

For a Boolean, you don’t need to type out the true/false, like you do for the 0/1 of a numeric variable. If the variable is true, you don’t need to type anything else, which is nice. Probably also makes it a little easier to spot typos or errors? That’s so subjective that I hesitate to hang too much on it, but it’s true for me.

Similarly, if you’re ready to try multireplace, it’s that little bit simpler with a Boolean variable. If your variable is numeric with possible values of 0 and 1, you could use multireplace a couple of ways:

@{(met_jones = 0) Introduce yourself to Jones.| "Oh hi, Jones."}

@{(met_jones+1) Introduce yourself to Jones.| "Oh hi, Jones."}

(These work for different reasons. The first version is testing the statement “(met_jones = 0)” as a Boolean… if it’s true that met_jones is zero, the first text snippet will be displayed, and if met_jones has any other value, you’ll get the second. The second version is testing met_jones as a numeric variable… but because numeric multireplace’s first text snippet is always for a value of 1, not 0, you need to add one to met_jones for it to work.)

Compare either of those to the Boolean multireplace:

@{met_jones "Oh hi, Jones."|Introduce yourself to Jones.}

I don’t know about you, but less hunt-and-pecking for the = and () signs is a small but meaningful quality-of-life difference for me when I’m writing. :slight_smile:

Before I started using multireplace more, I would also regularly *create a variable as 0, even if all the values checked in the game were in a short nonzero range. Because multireplace starts counting at 1, but must include an option for every value that’s actually reachable in the game, that had the annoying effect that I would need to test for (var+1) rather than var, and I’d often have no meaningful value for the first space:

Your alibi is @{(alibi+1) Nothing, this is alibi=0|Joe|Bubba|Mahershala}.

Now I much more often create the variable as 1, if I know it will only ever have a set number of positive values. That lets me just write, e.g.

Your forged name tag says "@{alibi Joe|Bubba|Mahershala}."

More on multireplace here. I honestly never thought I’d use it, but since I dove in a couple of years ago, it’s made it a lot quicker and tidier to code variations into my text. Especially in combination with macros, so I don’t need to hunt for @{ | }.

And with all that said: Do what works for you. :slight_smile:


One last comment. I gave this as the example of a simple Boolean multireplace:

@{met_jones "Oh hi, Jones."|Introduce yourself to Jones.}

but of course that can also work with a simple numeric met_jones. It would just be one where true and false are represented by 1 and 2, rather than 0 and 1 as you’ve been doing.

I can just about imagine a case where you’d need a true/false variable to be numeric. Say that you have the option to meet 10 different NPCs, and meeting any three of them is the threshold for something to happen. Once your met variables e.g. met_jones and met_smith and met_brahmacharya were added up (e.g. *if met_all = 3), you’d get the option to leave the room and do something more interesting. That might be easier to code using numeric variables than a whole bunch of Booleans.

But in a case like that, I’d still suggest setting false as 1 and true as 2 so you can use simple multireplace for flavor text around the individuals the MC has met. It’s easy to tweak the threshold (*if met_all = 6) to make that work.

All right, that’s all the complexity I’ve got to throw in response to a very simple question. :slight_smile:


Admittedly, I am going to have to pretend like I know how most of what you just said works, smile and nod.

That said, I appreciate the advice even if I don’t understand yet how multireplace works. Mostly I just needed to be sure that 0/1 wasn’t going to kick my code in the nuts five chapters in.

1 Like

It won’t. :slight_smile: It works, and you should do what works.

1 Like

One more quick question, unrelated to the topic.

      *if (Credits < 50)
        *hide_reuse #"Oh. I can't afford that, actually."
            *goto GenShop

This would work, right? The hide_reuse part I mean

The hide_reuse should work fine, but keep the *goto at the same indent level as the text.

1 Like

Thanks. Noticed it when I got home again.

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.