I know this issue has been comented in a lot of posts around here, but I still can’t have my through this error. I’ve encountered it a few times before and managed to get away, but now I can’t fix it and I don’t know what is causing it.
Today, I thought of develop a combat system for my Middle Ages era game, instead of writing the story. I created a new project on Choicescript IDE, so I could code it without Fing up something in the main code.
First, I created a simple system, based on a *rand command, and that worked. Second, I put some variables to it, like strength and agility to determine how well the character could swing an attack, or block one from the enemy. That also worked, then I went to the final phase which would be the implementation of weapon types. That worked… kinda, until it didn’t. A few bugs appeared out of nowhere and then I got this *choice bug, that I can’t fix.
As far as I know, there isn’t any *if without a *goto in the end. Now I don’t know what to do, please help.
Ooh, here’s the issue, I bet. Should that be “>=”?
I believe there’s no provision for agility being > 4, so the code is falling out without a *goto.
And I also think there’s no final *else in that sequence–it goes *if agility <= 1; *elseif agility =2; *elseif agility <= 4, and that’s it. But it’s hard to be wholly sure without seeing the proper indentation.
I’d recommend using a *fake_choice statement instead of a *choice, but I don’t know if that would hinder your chances at learning how to correctly use choices
This should work, feel free to copy and paste it. Let me know if you are still having issues. Also, there is no need to use the *elseif command if there are no overlapping variables, the *if command will work just fine.
It looks like I was wrong in my initial diagnosis. @Gower is right, the *elseif indentation is most likely the only cause. From what I can see, there is no need to change anything else. I also don’t see how your agility or strength could result in an error, it would just go to *elseif agility <= 4. That being said, make sure there is a space between the equal sign and the number.
So, I’ve just tested a little snippet of code, and there’s not an error if you don’t put an *else at the end of an if/elseif/else block.
For example:
*create var 0
*rand var 1 4
*if (var = 1)
*goto reeves
*elseif (var = 2)
*goto pitt
*elseif (var = 3)
*goto affleck
*label reeves
John Wick is my favorite movie!
*goto yea
*label pitt
Do you know Joe Black?
*goto yea
*label affleck
Christian Bale was a better Batman
*goto nay
*label yea
You won!
*ending
*label nay
You lost!
*ending
In that piece of code, CS would go to *label reeves if *rand var resulted in 4, but you could fix that putting the “affleck” label at the top of the if/elseif block
I know that this use of *ifs and *elseifs could lead to bugs, but if you code it in the right way, I don’t see why you need an *else