|
sabman Novice
Joined: 17 Aug 2007 Posts: 34
|
Posted: Mon Aug 27, 2007 5:59 pm
[2.01] Bug or Doc Problem with #MATH |
I'm not sure if this is a bug, my error, or a doc problem.
The math syntax is:
Syntax: #MAT varname expression
Yet when I do:
#MATH temp @amount + 1
It assigns the value of amount to temp and places temp in class 1, although this:
#MATH temp @amount+1
Works perfectly.
Nowhere in the doc does it say if the problem is spaced it needs to be in parenthesis. The syntax also doesn't show that there's a flag for class assignment.
Suggestion 1:
Change the doc to include a statement about spaces in equations and include an example like the one above, but correct. (#MATH temp (@amount + 1))
Suggestion 2:
Change the usage of math to follow suit like other functions (while/if/etc) So that the statement MUST be encapsulated in parenthesis or braces.
Suggestion 3:
Change the #MATH statement to not include any class assignment and instead process the statement after the second whitespace as the entire MATH problem. |
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Mon Aug 27, 2007 6:13 pm |
Just like most commands in zScript, if you need to use spaces, enclose your parameter in {}s...
#MATH temp {@amount + 1} should work fine :)
Otherwise the parser has to decide whether a space in your command call is a split for a separate argument, or if it's supposed to be part of the equation, which it cannot do. |
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
sabman Novice
Joined: 17 Aug 2007 Posts: 34
|
Posted: Mon Aug 27, 2007 6:19 pm |
Thinjon100 wrote: |
Just like most commands in zScript, if you need to use spaces, enclose your parameter in {}s...
#MATH temp {@amount + 1} should work fine :)
Otherwise the parser has to decide whether a space in your command call is a split for a separate argument, or if it's supposed to be part of the equation, which it cannot do. |
I agree. As a programmer, I usually enclose all my mathmatical equations just to be on the safeside, unless for some reason syntax doesn't allow.
And just why I mentioned it. Because the syntax first of all doesn't mention of a class assignement. Plus, all the examples are left unbounded. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Aug 27, 2007 6:36 pm |
You don't actually need to use #math - #var will do the same thing if you enclose its value parameter in brackets (). I'd assume that #math has a class parameter because it's exactly the same as #var, but always evaluates its value.
So with that said, I've added the class parameter to the #math help file. I don't think it needs anything beyond that, because zScript commands always have problems if items are unbound and contain spaces, even when there are no extra parameters. Take #additem, for example. |
|
|
|
sabman Novice
Joined: 17 Aug 2007 Posts: 34
|
Posted: Mon Aug 27, 2007 6:39 pm |
That's better, at least. If I had seen the class parameter, I'd have assumed.
When working with scripting languages like this, it can be hard to tell, because there's no standard.. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Aug 27, 2007 6:53 pm |
Well, there's an internal standard, and now you know :P
No commands actually allow multi-word unbounded parameters. The ones that look like they do actually take a variable number of parameters and do something with them all afterwards (like #say concating them all together with spaces between and printing them on the screen). So it's consistent, anyway.
If you're that bothered, use Lua ;) |
|
|
|
|
|