choicescript
choicescript copied to clipboard
Temporary variables cannot be initialized with negative values
*create test -5 and *temp num -5 each result in errors.
*title test
*author me
*scene_list
startup
test
*create test -5
*finish
yields
F:\Docs\Choice of Games\test>java -jar js.jar -w -opt -1 -debug autotest.js mygame
startup.txt executing QUICKTEST FAILEDError: startup line 8: Invalid create instruction, value must be a a number, true/false, or a quoted string: test -5
(and that error message duplicates the word "a"); also
*temp num -5
${num}
*finish
yields
F:\Docs\Choice of Games\test>java -jar js.jar -w -opt -1 -debug autotest.js mygame
startup.txt executing test.txt executing QUICKTEST FAILEDError: test line 2: Invalid expression at char 2, expected NUMBER, STRING, VAR or PARENTHETICAL, was: OPERATOR [-]
You can work around it like this:
*temp num 0-5
As for fixing it, this is a subtle issue. One thing that's clear is that users can't *set
a variable directly to a negative value, because this line:
*set num -15
already means "subtract 15 from num", not "set num to negative 15."
We could put some special-case code in *temp
to allow negative values, but I think it would be difficult to explain why *temp num -15
behaves so differently from *set num -15
.
Ah, that's a good point; I had forgotten how the overloaded *set
would interact with the whitespace-lenient basic math operators like -
in this case. Good thing I'd always initialized negative values at 0 first...
I'm surprised *temp num 0-1
works. I hadn't thought calculations could be done in any statement without parentheses. Regardless, this workaround isn't valid for *create
statements.
Proposed syntax:
*create num (-1)
and
*temp num (-1)
Parentheses are currently illegal in *set
and *create
statements, so I don't believe this should break existing code.
(I'd like to see *set num (-1)
allowed, as well. Parallelism, for one thing, but I also find this syntax is more clear and readable than (0-1)
.)