How can I have multiple conditions in an IF statement?
As a way of example below I want to do something along these lines in one passage but cannot find any examples.
<<if $box1==true and $box2==false and $box3=true>>
Blah blah
<<endif>>
<<if $box1==false and $box3==true>>
Different Blah blah
<<endif>>
Comments
<<set $foo = "true">><<set $voo = "false">>
<<if $foo eq "true" and $voo eq "false">>A winner is you!<<endif>>
Thanks for that Sharpe. Is there a limit to how many "and" "or" within a IF statement can be use?
Also is there a limit to how many IF conditions/statements you can have in one passage? because i have a few of them and it seems to be only passing the first If statement out of six I have in total. I am checking them with displaying the variables in their current state for debugging purposes and according to those some of the other IF conditions should be displaying the appropriate text but they are not. I am not seeing any error messages either, syntax is correct.
Surely you can have more than one IF statement in a passage?
Are you using <<else>>? Sometimes nested if conditional branches can be tricky.
Upload your story file and let's have a look.
This is my first go at a Twine story and I am experimenting with it as I go, its first draft as far as the writing goes and I will be polishing that side of it up last.
Here's my story file:
http://www.mediafire.com/view/ducd9h780l4rqsw/TheRaid_V1.tws
The passage im using multiple IF statements where I am having problems with is called "floor1A",
as stated the first If statement passes and when I play through (power cut was chosen earlier as an option) but the if powercut is true isn't outputting the paragraph when it should be. Neither any of the others if conditions are met.
These conditions are set in earlier passages of" Remotedet" or "sabotage1".
I was hoping to add some kind of basic combat system to make the game more dynamic, but its pretty much scripted so far which I might keep so its easier to track everything.
Secondly, I must be missing something because none of the passages you describe are in the game file. So, I think you posted the wrong file. XD
Take a look and re-up and I'll look it over.
Like I say, nested if's can be tricky. However, 1.4 has "else if's" that make them a lot easier.
Try this:
Thanks for your reply. I haven't touched twine today, but I will give your else if example a go, that might be the ticket. I always thought you could only use one else per if statement.
I am sure I have given you the correct file, there is only one. The passages you were looking for are on the very bottom left. The passage with the bunch of IF statements is to the left of the only two passages showing an orange !. Its a pity there isn't an info option that will tell you how many passages there are currently in total (including word count- not including code just for stat purposes) you have as that would be a good way to compare to files, but i suppose you can also go by file size.
The updated css you mentioned is on the Sharpe Stylesheet thread of yours right? I'm wanting to keep the look/style I currently have. When you add a <hr> line in, is there a way to set a colour for it too? I'll look into it tomorrow.
Thanks again for your help.
I do not know how to get everything looking as I had it before, with the stats list on the left and the target info at the top. Now its reverse, on the right side with the target info on the bottom and a gap at the top.
At present I have to scroll down the screen to read the rest of the intro, where as before it all displayed compactly on the screen with room to spare. Also is there a way to force word-wrap in a story region? one of the reasons in the previous version it looked skewed on your display was I had increased the border width to accommodate new
things I was adding to the inventory list as it would write over the top of the border. If I could word wrap it within the border then I don't need it so wide. I have reduced the font size to 16 but even the previous css version had larger text and could display all of it on screen.
How tricky is it to set it up the way you want versus how it will look on other peoples display configurations?
I will keep playing with it and see how it all works.
What?! I tested it on a friend's computer and it looked fine. Yeah, that's a problem. A big one, and it stems from the note I made about it not being centered how I would like to center it. I'll take a look.
Font-size is larger with Dumb Console. I think it was like 18 a long time ago, but I set it to the mid-20's later.
http://www.w3schools.com/cssref/css3_pr_text-wrap.asp
http://www.w3schools.com/cssref/css3_pr_word-wrap.asp
It's the real trick. The only way you'll know for sure is to check your file on other computers. I put mine on flash drive and run it on friend's computers often.
I noticed you have two posts, but I can't read the first right now.
It says for text-wrap "The text-wrap property is not supported in any of the major browsers."
This is the syntax So where does this go? I tried putting it in the storyregions and .passage and body sections of the stylesheet. But when i add a new item to the inventory its printing it over the border lines still.
There is an example at the top that looks slightly different Keeping the same stylesheet that you updated, i am also seeing when i click on a link it displays the new passage with everything to the left of the screen for a split second and then adjusts. So you get this jerky
flicker everytime. Sometimes the storyregion for the target info is displayed on the bottom left of the screen depending on what passage is showing. I'll paste the stylesheet code I have so you can have a look. My screen res btw is 1920 x 1080.
Here is my nested IF statements that I have changed as per your suggestions.
When I play through and I do cut the power, variable is set to true. It should be displaying the paragraph
[quote]With the power cut it should help a great deal. But its not. Its still passing the first IF statement but ignoring the others.
How do other people get around this, when you want to include some paragraphs in a passage if the player has made some earlier choices?
I checked again. In the file you posted, none of those passages are there and there is only one if branch: <<if $inv == "Radio">>
Unfortunately, the statement is pretty bewildering. So, there might be an issue somewhere in that jungle.
When I have problems with an if branch I print all the variables right before the branch (above $mackHealth in this case). Then, I know if a variable is at fault, or if it's the conditional branch.
However, if $mackHealth is 0, then that's the one that's going to hit no matter what is further down. It stops when if finds the first true stement. (EDIT: Highlighted, because this is probably the case. Also, note that in 1.4+, variables that are not set are by default 0. So, if you haven't set Mack's health, it's 0.)
Attached is a file with your if conditional branch. It seems to work, so the problem is probably in your variables. Use the file to help test your branch to make sure it's doing what you think it should.
I had previously uploaded my game file from my dropbox folder where I has been saving it. So to be sure I saved it into a normal folder and have uploaded it again. So now you should see those passages I have mentioned Floor1A is the one with the IF statements in question.
Link: https://www.mediafire.com/?4fxaif9q72f8i9d I haven't updated the storyregion Module, I am not sure if i already have the correct updated one, as before I did find a page that had some updated things to change. I believe it was adding some array variables.
Here is what I have for the StoryRegion Module currently. The nest of IF statements in the passage we are talking about does already have an output of those variables being checked. And my variables are set in the beginning of the game, in a passage called Varinit. I actually thought if a variable wasn't set at all it would throw an error, so I have been setting them all at the start.
Far as I can tell in my tests the variables have been correct.
Hopefully now you can view the proper version of my game in progress, those funny variable names makes a little more sense ;D i tried to make them descriptive enough so I can keep track of them as the game gets bigger.
[quote]However, if $mackHealth is 0, then that's the one that's going to hit no matter what is further down. It stops when if finds the first true statement.
Hmm..ok so what I am trying to do will not work then, so to be sure, it has to be only IF statement to be true and then it stops reading IF statements altogether in that passage? Why does it do that?
I want to be able to several output paragraphs in my game if certain conditions are met within one single passage. And these will be just different combinations of conditions.
If only one IF is passed then it means more work, having to create a new passage for every IF statement, this will clutter the work space up even more. As for right now perhaps the work around is with having a few <<display 'passage'>> and each of those passages will have a different IF statement with an output if true.
Surely it could be possible for the dev to make it so within one single passage each IF statement will be read regardless if they pass or fails. If there isn't then may I suggest this it for the next update?
This would be useful for games that are created to be dynamic with having alternative text or descriptions based on variables when a player returns to a passage/location, from descriptions of weather, time of day, npc conversations, other game world changes made by the player or scripted in, combat system.
I know some macros exist with <<once>> <<becomes>> etc but they are more restrictive and linear still. Handy if you do not want to repeat the beginning of a passage or whatever but that's it.
Let me know if you now can see those passages I have mentioned, they are down the very bottom.
Thanks for your help. Hopefully I will get all this sorted and move on ahead with my game. I am learning lots already.
In other words, "If Mack is dead, do this. If not, do one of these other things."
That should take care of the issue, I'll wager.
If not, and you really want all of the ifs to be read, then don't nest them. There were multiple updates to the SR code. Delete your SR passage and copy the one from Dumb Terminal.
The if conditional branch system works as it is intended to work and as it should work. You're just doing it wrong.
PS: I did take a quick glance at the game and there are more issues with the way you've set up your conditional branch. Can't go into it now, but it's not going to work.
Just for an example, for purposes of me and other new comers to twine can grasp what is the best way to to achieve having multiple conditions. The wiki seems to be lacking some information on this, well as far as my eyes can see.
So for an example in the previous passage the player was given three choices to choose from..
Choice A and Choice B and Choice C
And we want to keeping with consistency track a variable that may or may not be true based on an earlier choice in the game but want to reflect that outcome if true in the same passage. We will call this Variable X.
How would you in a single passage check if one of those choices are true and have an output for it, including the variable that makes 4 IF statements. To make it a little more tricky, what if Choice A and Variable X both being true will also have a unique output. So that brings it to 5 IF statements.
How would you guys go about it?
So here is my demo I made, I thought i'd make it available for others like myself who have struggled with it.
https://www.mediafire.com/?7gjmg2s60ixv23f
Or just look at the code for the multiple conditions Goes to look for a rock to crawl under..