Negative Number Issues

While I was working on my stats page, I came across a few issues with negative numbers. I’m uncertain if I’m doing something wrong or if the problem lies in ChoiceScript itself.

First off, in my startup scene, I am unable to create variables with default values below zero. For example, the following line of code:

*create pc_arcana -1

… Results in the following error:

“Invalid create instruction, value must be a a number, true/false, or a quoted string: pc_arcana -1”

Secondly, I am unable to use negative values in conditional statements, for example:

*if (pc_arcana = -1)

… Results in the error:

“Invalid expression at char 14, expected NUMBER, STRING, VAR or PARENTHETICAL, was: OPERATOR

I was able to circumvent both issues, but in both cases, they are less then satisfactory solutions. Any guidance is much appreciated, and thanks in advance!

1 Like

Sadly, CS doesn’t register negative numbers, so you’ll have to find some way around it.

Inconvenient. I’m not planning on any extensive use of negatives however, so I will live. Thanks for the heads up!

Np, man.

My first ever post to the forum was this very question: http://www.choiceofgames.com/forum/discussion/204/negative-stats#Item_4

My solution for conditionals was to do something like this:

*if ((pc_arcana + 1) = 0)

… Which is checking to see if pc_arcana = -1 in reality. Unfortunately, for creating variables, one has to set their value after creation.

2 Likes

Yeah - I think that’s unlikely to work well for most uses of variables, and so re-centering on (say) 50 rather than 0 is a more promising approach.

Of course it is still possible to have and use negative variables - for example, you can create a variable at 0 and then set it minus 1000. You just can’t create it as a negative number in the first place, or use it in conditional statements more precise than “*if stat < 0” (without elaborate addition setups like yours). In CoReb I’ve got several stats where you get a different effect when you go negative.

Yeah, definitely cumbersome. Luckily, I just need it as a flag to indicate the inability to use said stat. I suppose I could have just created a boolean, but oh well. I hate being a programmer sometimes :stuck_out_tongue: