Non-existent variable (warning lots of text!)

Not sure what is wrong, but it must be whole thing due to the fact that i deleted one and the next in line failed. I uploaded the whole thing sorry its so long!

stats
*temp threes_text ""
*if (threes < 3)
    *set threes_text "Look mom both hands!"
    *goto chart
*elseif (threes < 6 )
    *set threes_text "Better not blink!"
    *goto chart
*else 
    *set threes_text "Ankle Breaker"
    *goto chart
Stats part 2
*label chart
*line_break
*stat_chart
    text shooting_text Shooting Level
    text threes_text Threes Level
    text dunks_text Dunks Level
    text dribbling_text Dribbling Level
    text passing_text Passing Level
    text offense_text Offense Level
    text rebounding_text Rebounding Level
    text defense_text Defense Level
    text blocks_text Blocks Level
    text steals_text Steals Level
    text speed_text Speed Level
    text strength_text Strength Level
    text stamina_text Stamina Level
    text academics_text Academics Level
    text social_text Social Level
    text fame_text Fame Level
*line_break
Startup

*create shooting 0
*create threes 0
*create dunks 0
*create dribbling 0
*create passing 0
*create offense 0
*create rebounding 0
*create defense 0
*create blocks 0
*create steals 0
*create speed 0
*create strength 0
*create stamina 0
*create academics 0
*create social 0
*create fame 0

I think you have to be more specific, which variable did the error say was non-existent?

also, try using this
image
when showing code in the forum, helps people identify indentation and such
like this

Line one
    indented text

Cheers!

EDIT: I could very well be wrong, but… you might want to delete all those goto lines. Since with them, you skip all the other temp variables and head straight to the chart. And since your chart uses those very same temp variables you skipped… might cause problems.

I think that might be the problem, actually. Since you skipped over creating and setting those temps, they never existed in the first place.

1 Like

Ok I edited it down to one variable that is messing up, but it goes straight to the next one if I delete that variable.

If the goto is the error do I delete all or just a certain one?

All of them have to go.
The gotos actually are not required here, since the ifs and elses do their job of blocking lines that don’t match the stats.

Mhmmm, just as I thought. Since Shooting was completed with no problems, but the code jumped to the chart right after, it didn’t have a chance to create the other temps, and since Threes is the one that comes right after Shooting, it gets the error first.

Ok that makes since, but then do i put finish to replace them?

No, no, just leave them as-is.
The finish command ends the scene, you don’t want that! XD
Basically, without goto, the programs reads the next line, and so on.
And you won’t have to worry about it reading the other parts of the same if block you don’t want it to, since if blocks are special cases, where only one outcome is read.

*temp threes_text ""
*if (threes < 3)
    *set threes_text "Look mom both hands!"
*elseif (threes < 6 )
    *set threes_text "Better not blink!"
*else 
    *set threes_text "Ankle Breaker"

this should do it.

In addition, a good practice is to lump the creation of all temp variables at the beginning of their file, makes them easier to find later on.

Correct me if I’m wrong, but don’t you have to enable implicit flow control to prevent that from throwing error messages? Or is it enabled by default now?

2 Likes

so once i deleted the goto it is now saying it is illegal to fall out of a else statement without a finish or goto before the end of the indented block.

Depending on when you downloaded your ChoiceScript installation, the fastest thing to fix that is probably going back to your startup.txt and adding the following line in among the rest of your *create commands:

*create implicit_flow_control true

Assuming your CS installation is new enough, that will remove the error immediately. There ARE alternatives if that doesn’t work, however. Give it a try and report back to us, okay?

what @Minnow said
alternatively, you could do this:

*if (shooting < 3)
    *set shooting_text "Look mom both hands!"
    *goto checkthrees
*elseif (shooting < 6 )
    *set shooting_text "Better not blink!"
    *goto checkthrees
*else 
    *set shooting_text "Ankle Breaker"
    *goto checkthrees

*label checkthrees
*if (threes < 3)
    *set threes_text "Look mom both hands!"
    *goto checkdunks
*elseif (threes < 6 )
    *set threes_text "Better not blink!"
    *goto checkdunks
*else 
    *set threes_text "Ankle Breaker"
    *goto checkdunks

and so on and so forth, and then have the last check, fame, goto chart.

For clarity on the alternatives:

  • You could leave the *goto commands in place, but add extra *label statements between each block of *set commands, so that one block can jump to the next instead of jumping to the chart.
  • You could replace the *else and *elseif statements with carefully constructed *if statements.

@UmbraLamia just gave an excellent example of the first alternative.

The second alternative might look something like this:

*if (shooting < 3)
    *set shooting_text "Look mom both hands!"
*if ((shooting >= 3) and (shooting < 6))
    *set shooting_text "Better not blink!"
*if (shooting >= 6)
    *set shooting_text "Ankle Breaker"

*if (threes < 3)
    *set threes_text "Look mom both hands!"
*if ((threes >= 3) and (threes < 6))
    *set threes_text "Better not blink!"
*if (threes >= 6)
    *set threes_text "Ankle Breaker"

I don’t recommend this last method for most situations, as you’ll need to be very careful you haven’t left any “gaps” a player could accidentally slip through. For example, if one *if statement had read (shooting < 3) and the next had read (shooting > 3), ChoiceScript would have had no instructions on what to do when shooting was exactly 3. Bigger or smaller than 3, it could handle, but exactly 3? Error!

Still, if you’re careful, the option’s available. And who knows, maybe you’ll find a situation where you need a way for some players to slip through the gaps on purpose.

1 Like

I had to gave it a rest last night due to going to work. When I get home ill use everyones suggestions and find the best way from above examples! Thanks again ill be sure to update.

1 Like

@Minnow @UmbraLamia

NVM! solved it myself once I posted in here and saw the spacing errors!

Seems like you have a space next to your underscore

Edit: :stuck_out_tongue:

1 Like

Thank you everyone so very much!

1 Like