Can't use negative numbers as parameters.
soliddanii opened this issue ยท 8 comments
When I try to use negative numbers the executor gets the wrong arguments. The plugins tryies to operate with those numbers before handling the arguments to the executor. In this particular case i want to sepecify negative coordinates as a location. See image. The last number is substracted to the second.
Now you can use both space and ',' for argument separator.
/trg run #WORLD:LEVERTOGGLE -14341, 82, -1716
will work.
(New refactored version is still under heavy testing. Expect some bugs!)
Ok so i tested it and now i can use ',' and ', ' but not just a space. Is that right?
No, you can still use spaces.
You can even add space and commas together.
I don't know if it's a good design, but I didn't want to break the functioning Triggers that uses spaces for separator
I was asking because with the latest build (172) i still can't use just spaces. Commas and commas with spaces work fine, but spaces don't:
Command:
/trg run #WORLD:LEVEROFF -14341 82 -1716
Parameters the executor is getting:
Number of parameters: 2
Parameter 1: -14341
Parameter 2: -1634
Error:
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:598)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:267)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:141)
at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:217)
at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.run(AbstractTriggerManager.java:202)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.Exception: #LEVEROFF encountered error.
at io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager$JSExecutor.execute(AbstractExecutorManager.java:266)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:327)
... 5 more
Caused by: java.util.concurrent.ExecutionException: javax.script.ScriptException: Error: Invalid parameters. Need [Location] in at line number 44 at column number 2
at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftFuture.get(CraftFuture.java:74)
at io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager$JSExecutor.execute(AbstractExecutorManager.java:264)
... 6 more
Caused by: javax.script.ScriptException: Error: Invalid parameters. Need [Location] in at line number 44 at column number 2
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:392)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
at io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager$JSExecutor$1.call(AbstractExecutorManager.java:245)
at io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager$JSExecutor$1.call(AbstractExecutorManager.java:232)
at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftFuture.run(CraftFuture.java:89)
at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:356)
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:832)
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423)
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:766)
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:664)
... 1 more
Caused by: :44:2 Error: Invalid parameters. Need [Location]
at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:102)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:106)
at jdk.nashorn.internal.objects.NativeError.(NativeError.java:110)
at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129)
at jdk.nashorn.internal.scripts.Script$Recompilation$32$914A$\^eval\_.LEVEROFF(:44)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386)
... 10 more
Sorry, for that case, you have no choice but using comma to separate them.
It's because TriggerReactor first tokenize the source code and then parse it one by one.
For example, even if you wrote -14341 82 -1716, after the lexical analysis, it becomes -, 14341, 82, -, 1716 total of five tokens.
Therefore, parser really has no ability to distinguish between 82 - 1716 or 82 and -1716 as they are the same for the parser.
Or, you can first save negative value in the variable and use it for the Executor
x=-14341;y=82;z=-1716;#WORLD:LEVEROFF x y z
Negative numbers are proving to be a real problem. Now #LEVEROFF works if I use commas to separate the numbers, or if I first set the value in the variable as you say, but for example #ITEMFRAMEROTATE, that has a string argument before the numbers only works setting the variables beforehand. Simply separating the numbers with commas produces an error.
Command that works:
/trg run x=-14343;y=82;z=-1716;#WORLD:ITEMFRAMEROTATE "FLIPPED" x y z
Command that doesn't work:
/trg run #WORLD:ITEMFRAMEROTATE "FLIPPED" -14343,82,-1716
Error:
io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException: Error occured while processing Node [type: OPERATOR_A, value: '-'] {([type: STRING, value: 'FLIPPED']) ([type: INTEGER, value: '14343']) }
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:598)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:267)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:263)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:141)
at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:217)
at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.run(AbstractTriggerManager.java:202)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
at io.github.wysohn.triggerreactor.core.script.Token.toDouble(Token.java:69)
at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:361)
... 6 more
The executor doesn't even start, doesn't even process the first sentence.
Not beeing able to use negative numbers seamlessly like positive ones is not very user friendly. Can something be done in the parser for it to recognize unary minus?
Thank you.
But it's definitely not a good practice to combine both space and comma as it just looks confusing.
I would suggest you to go like this:
/trg run #WORLD:ITEMFRAMEROTATE "FLIPPED", -14343, 82, -1716
The error is basically complaining that it is trying to convert "FLIPPED" into number in order to work on the subtraction, but it couldn't as "FLIPPED" is not number at all.
Obviously, you can assume that it thinks it has to subtract 14343 from "FLIPPED" not thinking it as parameter.
Minus is trouble maker for sure, but there is no better way to distinguish between subtraction and unary minus for those cases.