Trouble with different scenes with *if statement

I’m having trouble with creating different scenes that depend on a previously made choice.

The error I’m getting is is that even though I’ve added the *if statement in my code as well as the startup screen, a long wall of text with both the different scenes appear when I playtest my game, even though only one should.

My code looks like this in the actual file:

*if mc_took_knife = true

Moving away from him, you quickly duck down to reach for your knife, allowing a triumphant smirk to blossom on your lips as you wrap your hand around the worn handle. 
*goto distraction1
  
*if mc_took_knife = false

Moving away from him, you look for a way to get away from this asshole. [i]Fast.[/i]
*goto distraction2

And I’ve added this to my startup file:

*create mc_took_knife false

I’ve tried looking on here, but all I found were scenes that change depending on stats. Can anyone help out? :confused:

1 Like

Try like this.

*if mc_took_knife = true
  Moving away from him, you quickly duck down to reach for your knife, allowing a triumphant smirk to blossom on your lips as you wrap your hand around the worn handle. 
  *goto distraction1
*else
  Moving away from him, you look for a way to get away from this asshole. [i]Fast.[/i]
  *goto distraction2
1 Like

Can you show what your code looks like at the distraction1 and distraction2 labels? My guess is that you have both scenes coded one after the other and don’t *goto at the end of distraction1 in order to skip distraction2—so when mc_took_knife is true, you end up going to distraction1 as intended, but then naturally fall into distraction2 and end up seeing both.

The code looks like that there

*if mc_took_knife = true
  Moving away from him, you quickly duck down to reach for your knife, allowing a triumphant smirk to blossom on your lips as you wrap your hand around the worn handle. 
  *goto distraction1

*if mc_took_knife = false
  Moving away from him, you look for a way to get away from this asshole. [i]Fast.[/i]
  *goto distraction2

*label distraction1

He takes a swing at you with his free hand and a second too late do you realize that that was just a diversion.

Some more text.

*label distraction2

He takes a swing at you with his free hand and a second too late do you realize that that was just a diversion.

Some more text.

So yeah, I coded the scenes right after one another. How do I fix it?

@Loudbeat I tried adding the *else line but it didn’t change anything. :frowning:

Right, so what’s happening is that when the code is done running through distraction1, it doesn’t realize that you don’t want it to go through distraction2—from a coding perspective, distraction2 is what comes next, so the code just continues to run the file from top to bottom as normal, from the start of distraction1 to the end of distraction2. What you need to do is cut this off and skip distraction2 by putting another label after distraction2, and then *goto it at the end of distraction1. Like so:

*label distraction1
[...]
*goto afterdistraction [or whatever you choose to name this label]

*label distraction2
[...]

*label afterdistraction
[Whatever comes next]
3 Likes

Yes, thank you so much!!! It works perfectly now :smiley:

Yes, I see now, the solution is what @CorvusWitchcraft said. The program that reads the code will keep going to the subsequent label if there isn’t a *goto, so from the distraciton1 the next label is distraction2 and that’s what it’s showing you.

Anyway, you could also use my suggestion on the *if command and even a simpler way would be

*if mc_took_knife
  text
  *goto distraction1

*else
  text2
  *goto distraction2

I don’t remember if the *if mc_took_knife should be *if (mc_took_knife) or not, but afaik the if by default checks if it is true. I have the idea this was explained somewhere.

2 Likes

Ohh, now I get what you mean. Thank u! I’ll try that way as well :smiley:

1 Like

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