Can you use *if within choices?

Hi guys I’ve been looking at this code and can’t work out what’s wrong with it. I’m guessing maybe I can’t use *if statements within choices?

The error with quicktest is
Error: part4 line 167: It is illegal to fall out of a *choice statement;
you must *goto or *finish before the end of the indented block.
The spacing should be right I think, so wondering if it’s the *if’s that is messing it up or something else? (The error relates to the line with “throw the knife”) Thanks :slight_smile:

                        *choice
                            #Get in close and slash with the knife.
                                *if ( agility > 39 ) 
                                    Story here
                                    *goto attackfail
                                    
                                *if ( agility < 40 )
                                    *set health -10
                                    *set part4injured 1
                                    Story here                                         
                                    *goto attackfail 
                                     
                                
                                    

                             
                            
                            #Throw the knife from where you stand.
                            
                                *if ( strength > 39 ) 
                                   Story here                                     
                                   *goto attackfail

Due to the way Quicktest works, the test doesn’t realise that a player will default to either (agility > 39) or (agility < 40).

You can solve it with *else, like this:

*choice
                            #Get in close and slash with the knife.
                                *if ( agility > 39 ) 
                                    Story here
                                    *goto attackfail
                                    
                                *else
                                    *set health -10
                                    *set part4injured 1
                                    Story here                                         
                                    *goto attackfail 
                                     
                                
                                    

                             
                            
                            #Throw the knife from where you stand.
                            
                                *if ( strength > 39 ) 
                                   Story here                                     
                                   *goto attackfail

If you have a string of qualifiers - if you wanted to check for ((strength > 10) and (strength <= 20)) AND ((strength > 20) and (strength <= 30)) AND ((strength > 30) and (strength <= 40)), for instance - you can use a string of *if, *elseif, and *else, as well, like this:

*if ((strength > 10) and (strength <= 20)
    *goto thirdplace
*elseif ((strength > 20) and (strength <= 30))
    *goto secondplace
*else
    *goto firstplace

As long as the *else is at the end, without a qualifier (to cover any other options not specified in the code), it should work without breaking Quicktest.

9 Likes

Thanks so much! All fixed :smiley:

1 Like