So, one of the things I didn’t understand (as someone who never coded anything before doing my game) until very recently was how to make sure I was coding ‘or’s’ and ‘and’s’ in my *if statements correctly. Then, I taught myself how to read the statements. Then I realized a really easy shortcut to making sure the parenthesis added up correctly. I’ll use one of my upcoming Text Box Investigation sequences as an example.
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or ((currentclue = "Water Pipe"))) or (((currentclue = "water pipe")))) or ((((currentclue = "Water pipe")))))
To give some context, the variable currentclue
is being typed in by the PC via a text box. So if they type in apple
then currentclue
is set to apple
. This may be a lot to look at for someone new to coding, so let me break this into bite sized pieces. First, let’s go through a statement that’s not comparing anything. A simple statement for a single variable with different outcomes like the one above.
First thing I want you to do is count the amount of variables that are included in this long string of ‘or’ statements. So essentially, how many times does currentclue
pop up? Five times. Congrats, first step done! Seriously, once you know that, the rest is really easy!
Second thing I want you to do; look at each end of the total statement, where there’s the most parenthesis stacked on top of each other like an American fast food burger. The very left, right after *if
and at the very right. Now you’re going to count the number of parenthesis on each side. Do they match the amount of currentclue
variables in the statement? As in, do the left and right sides each have 5 parenthesis each? There ya go! That’s step two! Make sure the amount of parenthesis on the far ends of the full statement match the amount of variables in your statement.
It will look like this:
*if (((((currentclue = "Pipe" or currentclue = "pipe" or currentclue = "Water Pipe" or currentclue = "water pipe" or currentclue = "Water pipe")))))
Third thing I want you to do is enclose every one of those statements in just a regular set of parenthesis, but don’t add anymore onto the ends. So at this point, it will look like this:
*if (((((currentclue = "Pipe") or (currentclue = "pipe") or (currentclue = "Water Pipe") or (currentclue = "water pipe") or (currentclue = "Water pipe")))))
Now you’ve determined where your individual statements are. Easy, right? Basically what is starting to take shape is that, if the player types in Pipe
pipe
Water Pipe
water pipe
or Water pipe
into the text box it will take them to the same place. That is the goal of this exercise.
Okay, fourth step. Start on the VERY LEFT of the statement. Those 5 parenthesis after the *if
. I want you to focus on going to the end of each INDIVIDUAL STATEMENT. The parenthesis on the right of each individual statement, are going to be whatever numbered statement it is in the sequence. So, "Pipe"
is the first statement in the sequence. Therefore, it has 1 parenthesis at the end of it. "pipe"
is the second statement in the sequence, so it’s going to have 2 parenthesis at the end of it. Keep doing that until the end, where the fifth and final statement "Water pipe"
already has 5 parenthesis at the end of it.
So now, it’s going to look like this:
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or (currentclue = "Water Pipe"))) or (currentclue = "water pipe")))) or (currentclue = "Water pipe")))))
Finally, for every individual statement in the sequence except the first one, count how many parenthesis are at the end of it, then subtract 1. For instance, going from right to left, the very last statement has 5 parenthesis at the end of it. So, do 5 - 1 = 4. You will put 4 parenthesis in the beginning of that individual statement. The end result is the correct sequence of code!
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or ((currentclue = "Water Pipe"))) or (((currentclue = "water pipe")))) or ((((currentclue = "Water pipe")))))
That sequence makes it so if a player types in any of those variations of Pipe
or Water Pipe
that it will take them to the same text passage. You can add as many sequences as you want to a line of code like this, as far as I know! So if you’re coding the introduction to your game, and you don’t want to allow the player to pick a variety of names, it could look something like this!
*label entername
*if (((((((((((((name = "Elizabeth") or (name = "Liz")) or ((name = "Art"))) or (((name = "Arthur")))) or ((((name = "Kris"))))) or (((((name = "Kristina")))))) or ((((((name = "Chris"))))))) or (((((((name = "Christina")))))))) or ((((((((name = "Sam"))))))))) or (((((((((name = "Samuel")))))))))) or ((((((((((name = "Sarah"))))))))))) or (((((((((((name = "Carter")))))))))))) or ((((((((((((name = "Harper")))))))))))))
*goto nametaken
*label nametaken
This is the name of a prominent character in the story, apologies! Please pick another name!
*goto entername
If you can understand this concept, you can compare multitudes of variables as well! Just remember, choicescript only allows two total sequences of comparison. So again, going with the basics. Let’s use our last line of finished code we just did.
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or ((currentclue = "Water Pipe"))) or (((currentclue = "water pipe")))) or ((((currentclue = "Water pipe")))))
Now say we want to take them to that text sequence if they type in any of that, but only if they have enough Intelligence. It would then simply look like this:
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or ((currentclue = "Water Pipe"))) or (((currentclue = "water pipe")))) or ((((currentclue = "Water pipe"))))) and (Intelligence >= 25)
Checking the intelligence is the second variable out of 2 total. That’s simple! But what if you have more than two variables? Well, you check them all inside of a single sequence. You use the same exact thing you did in the first sequence, but instead, start it fresh from the second!
So if you wanted to check for Intelligence
and Awareness
and if they found the Water Line
earlier as a previous clue, it would look like this:
*if (((((currentclue = "Pipe") or (currentclue = "pipe")) or ((currentclue = "Water Pipe"))) or (((currentclue = "water pipe")))) or ((((currentclue = "Water pipe"))))) and (((Intelligence >= 25) and (Awareness >= 20)) and ((foundwaterline = "True")))
So now it’s checking if the player typed in any of the phrases they needed to in order to look at the clue, and it’s checking if the stats are high enough, and it’s checking if the variable for finding the Water Line
equals True
or not. This full sequence means:
If they type in Pipe
, pipe
, Water Pipe
, water pipe
or Water pipe
, and if their Intelligence is >= 25
, and if their Awareness is >= 20
, and if the variable foundwaterline = "True"
, only then will the player be taken to the appropriate text.
This is a key feature for how I do text box investigations in The Bureau, and I hope by following this step by step tutorial, more people will be willing to add fun little text box mini-games into their games as well! Happy writing/coding, and remember, everyone starts somewhere!
P.S. If any of this is wrong, someone more knowledgeable than me, please let me know below and I will be sure to fix it. This should all be correct though, as I tested it in my game and it did work.