Variable is not a number error

I’m having a bit of trouble, and I don’t know if I’m doing something that’s not possible, or what.

What I’m trying to have done is, a few choices raise up certain stats. At the end I’m trying to make it pick out the highest stat. I’ve searched through the forums to get an idea but it’s just not working for me.

For a better idea, the coding looks a bit like this-

*create var1 0
*create var2 0


*choice

(I might have accidentally posted a half finished post. Apologies!)

I’ve been getting an error that makes it past quicktest but not when playtesting the game. I have a couple variables that are number based, and at the end I want them to be compared and the highest chosen.

It goes a bit like this-

*create var1 0
*create var2 0
*create var3 0

*temp highest_variable
*set highest_variable {var3}

Some words and things.
*choice
     #Choice 1
           *set var1 + 1
     #Choice 2
            *set var2 + 1
     #Choice 3
             *set var3 + 1

then a couple more choices to raise further. Further down the line, I have this-

*label calculate
*if var1 > highest_variable 
   *set highest_variable "var1"
*if var2 > highest_variable
   *set highest_variable "var2"

And so on. When I playtest, it stops when it gets to *label calculate, and throws an error that says “not a number: var1”

I’ve been scratching my head at this for a little while, and hoping I’m just overlooking something. (Also, if you know a better way to find out which variable is the highest, I’d appreciate it because there’s a lot more than just 4 variables).

You are setting highest_variable to a string that says ‘varX’, the system doesn’t recognise that this is a reference to a different variable, and as a string isn’t a number, it can’t use it to determine which is highest. You are asking it to check if X is higher than the text varX.

A way to do this (but probably not the most effecient) is to go:

*if var1 > var2
    *if var1 > var3
        *set highest_variable "var1"
    *if var1 < var3
        *set highest_variable "var3"
*if var1 < var2
    *if var2 > var3
        *set highest_variable "var2"
    *if var2 < var3
        *set highest_variable "var3"

But this gets a lot more complex for every variable added, and doesn’t take into account if two variables can be equal.
If the highest can never be equal to another, but the lower two can, you can add:

*if var1 = var2
    *set highest_variable "var3"
1 Like