CS skipping over *if statements?

You’re using multiple sets of if-elseif statements for mutually exclusive conditions on the top level, particularly line 80 and line 96 using if despite being alternatives to the if-elseif statement starting at line 7.

I think that isn’t the problem in this case, but it makes it harder to be sure exactly what path it’s following through the code; it means you could theoretically trigger one of the ifs and the final else in one go. It looks like you’d always get some text from the first if in that case, though.

What are the values of each of the following variables in your test?

pronoun
romance
harry
draco
hermione
luna

Which ending are you trying to achieve and which one are you actually achieving? (Which of the ending labels actually appear?)

pronoun = hehim
romance = male
harry = 46
draco = 33
hermione = 100
luna = 19

The ending I want to reach with these variables should be that first “Harry” ending since his number is higher than Draco’s in this case. However when I run the test I end up in the “theythem” “either” Hermione GG ending. Which is… totally off course.

I’ve saved my old code in a different file and now I’m trying to build it a different way to see if I can isolate where it’s getting off course.

I’m not sure if it’s just pastebin being weird, but I can’t see any indents on any of the text that’s within the ifs and else-ifs that compare the numbers…

Oh, wait… I guess there are some? It’s kinda hard to see. CSIDE had me get used to the indents being super large…

Well, because of the split if-elseifs I mentioned, you technically meet the conditions for both that Harry ending and the Hermione GG ending simultaneously.

Still, there’s something else wrong, since you should reach the Harry ending’s *ending statement before getting to line 96 and winding up at the Hermoine GG ending.

Would it work better to have a set of *if *elseif statements for “pronoun” and nest the *if *elseif statements for romance inside of each of those?

I added some things to help you test the code you pasted.
Just copy and paste this into a startup.txt file.

Code
*title Title
*author Author

*create pronoun "hehim"
*create romance "female"
*create harry 1
*create draco 1
*create hermione 1
*create luna 1

*label main

END OF EVENT PARAGRAPH
 
${pronoun} ${romance}
  
*if ((pronoun = "hehim") and (romance = "male"))
 
 *if (harry = draco)
  FUCK A
  *goto variablechange
 
 *elseif (harry > draco)
  harry Ending FUCK B
  *goto variablechange
 
 *elseif (draco > harry)
  draco Ending FUCK C
  *goto variablechange
 
 *else
  FUCK IT'S THE MATH
  *goto variablechange
 
*elseif ((pronoun = "hehim") and (romance = "female"))
 *set harry * 0
 *set draco * 0
 
 *if (hermione = luna)
  MARY SUE ENDING FUCK D
  *goto variablechange
 
 *elseif (hermione > luna)
  hermione Ending FUCK E
  *goto variablechange
 
 *else
  luna Ending FUCK F
  *goto variablechange
 
*elseif ((pronoun = "hehim") and (romance = "all"))
 
 
 *if (((luna > draco) and (luna > hermione)) and (harry < luna))
  luna ending FUCK G
  *goto variablechange
 
 *elseif (((harry > draco) and (harry > hermione)) and (harry > luna))
  harry Ending FUCK H
  *goto variablechange
 
 *elseif (((draco > harry) and (draco > hermione)) and (draco > luna))
  draco Ending FUCK I
  *goto variablechange
 
 *elseif (((hermione > draco) and (harry < hermione)) and (hermione > luna))
  hermione Ending FUCK J
  *goto variablechange
 
 *else
  Mary Sue Ending FUCK K
  *goto variablechange
 
*elseif ((pronoun = "sheher") and (romance = "male"))
 *set hermione * 0
 *set luna * 0  
 
 *if (harry = draco)
  MARY SUE ENDING FUCK L
  *goto variablechange
 
 *elseif (harry > draco)
  harry Ending FUCK M
  *goto variablechange
 
 *else
  draco Ending FUCK N
  *goto variablechange
 
*if ((pronoun = "sheher") and (romance = "female"))
 *set harry * 0
 *set draco * 0
 
 *if (hermione = luna)
  MARY SUE ENDING FUCK O
  *goto variablechange
 
 *elseif (hermione > luna)
  hermione Ending FUCK P
  *goto variablechange
 
 *else
  luna Ending FUCK Q
  *goto variablechange
 
*if ((pronoun = "sheher") and (romance = "all"))
 
 END OF EVENT
 
 
 
 *if (((luna > draco) and (luna > hermione)) and (harry < luna))
  luna ending FUCK R
  *goto variablechange
 
 *elseif (((harry > draco) and (harry > hermione)) and (harry > luna))
  harry Ending FUCK S
  *goto variablechange
 
 *elseif (((draco > harry) and (draco > hermione)) and (draco > luna))
  draco Ending FUCK T
  *goto variablechange
 
 *elseif (((hermione > draco) and (harry < hermione)) and (hermione > luna))
  hermione Ending FUCK U
  *goto variablechange
 
 *else
  Mary Sue Ending FUCK W
  *goto variablechange
 
*elseif ((pronoun = "theythem") and (romance = "male"))
 *set hermione 0
 *set luna 0  
 END OF EVENT
 
 
 
 *if (harry = draco)
  MARY SUE ENDING FUCK X
  *goto variablechange
 
 *elseif (harry > draco)
  harry Ending FUCK Y
  *goto variablechange
 
 *else
  draco Ending FUCK Z
  *goto variablechange
 
*elseif ((pronoun = "theythem") and (romance = "female"))
 *set harry * 0
 *set draco * 0
 END OF EVENT
 
 
 
 *if (hermione = luna)
  MARY SUE ENDING FUCK AA
  *goto variablechange
 
 *elseif (hermione > luna)
  hermione Ending FUCK BB
  *goto variablechange
 
 *else
  luna Ending FUCK CC
  *goto variablechange
 
*else
 
 
 *if (((luna > draco) and (luna > hermione)) and (harry < luna))
  luna ending FUCK DD
  *goto variablechange
 
 *elseif (((harry > draco) and (harry > hermione)) and (harry > luna))
  harry Ending FUCK EE
  *goto variablechange
 
 *elseif (((draco > harry) and (draco > hermione)) and (draco > luna))
  draco Ending FUCK FF
  *goto variablechange
 
 *elseif (((hermione > draco) and (harry < hermione)) and (hermione > luna))
  hermione Ending FUCK GG
  *goto variablechange
 
 *else
  Mary Sue Ending FUCK HH
  *goto variablechange


*label variablechange

..........

Current situation:

Pronoun = ${pronoun}
*line_break
Romance = ${romance}
*line_break
Harry = ${harry}
*line_break
Draco = ${draco}
*line_break
Hermione = ${hermione}
*line_break
Luna = ${luna}


Change a variable?
*choice
 #All done (restart with current changes)
  *goto main
 #Pronoun
  *choice
   #Set to "hehim"
    *set pronoun "hehim"
    *goto variablechange
   #Set to "sheher"
    *set pronoun "sheher"
    *goto variablechange
 #Romance
  *choice
   #Set to "male"
    *set romance "male"
    *goto variablechange
   #Set to "female"
    *set romance "female"
    *goto variablechange
   #Set to "all"
    *set romance "all"
    *goto variablechange
 #Harry
  Harry: Choose from 1 to 100.

  *input_number harry 1 100
  *goto variablechange
 #Draco
  Draco: Choose from 1 to 100.

  *input_number draco 1 100
  *goto variablechange
 #Hermione
  Hermione: Choose from 1 to 100.

  *input_number hermione 1 100
  *goto variablechange
 #Luna
  Luna: Choose from 1 to 100.

  *input_number luna 1 100
  *goto variablechange
 
1 Like

The indent of the file is one space.

There are no *elses for the larger *if sections up to line 96, so once the bigger conditions are not being met, it will end up there; the game will at the very least reach line 175 if no conditions are met.

Anyway I tested your code with the values you sent and it worked fine, but I added a few conditions. Can you try replacing lines 7 through 23 with the excerpt below?

*if ((pronoun = "hehim") and (romance = "male"))
 *if (harry = draco)
  harry and draco Ending A
 *elseif (harry > draco)
  harry Ending B
 *elseif (draco > harry)
  draco Ending C
 *else
  ERROR ELSE #1
  *ending
*else
 ERROR ELSE #2
 *ending

Using the values you described to me, it worked just fine.

Example

…so I found the problem. :woman_facepalming:

I have the code in the ending file set to read for “male” and “female”, but I set the variables for romance to “men” and “women” in the startup file.

Which I saw in the variable test at the top, but my brain said “Ah yes, men is the same as male and coding will pick that up.” Even though I know it doesn’t.

Thank you everyone for helping me.

2 Likes

Mistakes are made when you write thousands of lines of code in the middle of the night for 5 hours.

1 Like

Well, I recommend you switch to using tabs instead of spaces for your indentation; a lot more visible with little key presses (one tab goes as far as like 4 spaces but with only 1 press for each indentation, a lot easier to handle).

I also recommend using CSIDE to make your coding and testing easier, if you aren’t using it already.

Thank you. How does CS do with wrapped text in case of hitting the end of a line? I probably won’t ever nest that many commands, but it’d be good to know just in case.

I will look into CSIDE! I was just using Notepad for now because I just started trying ChoiceScript yesterday. It’s been a interesting script to learn.

Hmm what do you mean? Like in the code if it reaches the end or in the game?

While playing the game it line wraps automatically; if you’re talking about the code it depends if the editor you are using has line wrap on or not. If it doesn’t, it will keep going endlessly and you’ll need to scroll horizontally which is a pain. If line wrap is on it will automatically move the code to the next line (without requiring pressing the return key). So you don’t have to worry about indenting a lot if you use tabs, it will work fine.

CSIDE has an option to turn code line wrapping on or off.

Line wrap on

Line wrap off

And yeah, don’t bother with Notepad. Use either CSIDE or an improved text editor such as Notepad++, Atom or Sublime.

1 Like

I was asking about the second instance of text wrap that you described. Good to know. CSIDE is what I’ll try out in a bit. Right not though I have to go through and fill in all the actual text and story so I can turn this project in.

I’m sort of kicking myself for not playing around and figuring out how to work with *goto and *label earlier. That probably would have made some of the code neater, but I’ll know to experiment with it next time.

Edit: CSIDE COLORS THE SCRIPT. YES. That’s so useful oh man.

1 Like

Fun fact, if you use Notepad++ you can make your own color schemes :slight_smile:

Such as this one I did

So does notepad+++ actually :slight_smile:
CSIDE dose have more choicescript specific commands built in than notepad+++ though. So whichever you prefer using. (I use both of them for different things.)

BTW @GoldenSilver, I’m not sure you have enough tabs open XD

1 Like

Well, I’d at least advise making there be only one if at each level when you only want to do one of the things, especially if you are using a final else. Essentially, if you didn’t have the *ending you’d get the Harry Ending then the Hermonie Ending with the variables you’d listed (“male” being correct). Which meant I had to examine the whole body of the first if to make sure it wasn’t that you’d missed a case in there so you went into that if and did nothing then got to the final else.

For a great many things in programming, including this, there are many ways to write code to obtain more-or-less the same result (performance may vary, but for choicescript I wouldn’t bother worrying about it) but some are preferred for readability and being easier to avoid screwing up.

As for nesting, I would have recommended doing it for this one and it would’ve revealed it was “romance” and not “pronoun” that had the problem, but now that it’s written I wouldn’t bother rewriting it.

also, sidenote:
Hope you just did this for testing and not to get it published, cause copyright etc…

Lol, it’s hard to believe J.K. Rowling would copyright the phrase “MARY SUE ENDING FUCK D” :laughing:

1 Like

It’s self published for free because it’s an interactive fan-fiction built with the choice script system. Fair use laws alone make this a viable method, and I read through the choice script terms and since it’s not published through their site it doesn’t seem to be an issue. Beyond that it’s also just a school project meant to explore the uses of interactive fiction and the way the text interacts with gender, sexuality, and identity in ways that the canon text and traditional fan-fiction can’t.

Thanks again guys for helping me out with finding the coding error so that I could actually turn this in. I just got my grade and commentary from my Professor. B+ (only because I forgot to support my arguments in my artist’s statement with specific course readings), and she wants to show it to future classes because of the amount of work I put into it.

1 Like