Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary variables cannot be initialized with negative values #111

Open
ChrisPC opened this issue Mar 4, 2016 · 2 comments
Open

Temporary variables cannot be initialized with negative values #111

ChrisPC opened this issue Mar 4, 2016 · 2 comments

Comments

@ChrisPC
Copy link

ChrisPC commented Mar 4, 2016

*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 FAILED

Error: 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 FAILED

Error: test line 2: Invalid expression at char 2, expected NUMBER, STRING, VAR or PARENTHETICAL, was: OPERATOR [-]

@dfabulich
Copy link
Owner

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.

@ChrisPC
Copy link
Author

ChrisPC commented Apr 1, 2016

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).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants