Runtime error when calculating distance between different worlds#8196
Runtime error when calculating distance between different worlds#8196sovdeeth merged 7 commits intoSkriptLang:dev/featurefrom
Conversation
|
Personally I'm against this change, with how skript acts in most cases like these it makes sense for it to return nothing |
|
Someone in the skunity discord also brought up that this would hard crash if someone does |
|
I think this change is fine, but given the change to behavior with things like math, it may just be better to tell people to check the worlds of two locations if they think they may be different. A runtime error would help with that (specifically for differing worlds, not null values). No strong feelings either way. |
|
With the possibility of a hard crash when returning infinity, instead of having it error and tell them to check manually, I think the second option might be better. Additionally things could stay as is, which is more seamless, but can trip you up badly. (That's the original reason I wanted some change) |
|
I would have to ask how to properly throw a runtime error in skript though. |
|
you should just be able to call |
Should I just do that in this PR? |
|
Sure, if ya want |
|
When I call I had someone argue in my dms that a hard crash would already happen if players went sufficiently far apart. Just putting that out there, not sure what to do with it. |
you return null, to maintain existing behavior. |
|
Honestly I am slightly unsatisfied with just a runtime error, but I have the changes ready to go. I ran the test suite locally again and tested on a server (It gives none and an error when in different worlds (wow)). I am kind of asking for confirmation on this being the wanted result. |
|
Yes, that seems like what should be done. |
suggestion made by sovdeeth Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
|
Oh god i merged bogus code, because I thought the dots where just some end of line width thing i couldn't unwrap. Whoops |
suggestion by sovdeeth
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
|
Ah just missing an import for Classes and it should be good after that |
sovdeeth
left a comment
There was a problem hiding this comment.
wonderful; thank you for the pr, as well as all the analysis around infinity/null behavior!
…iptLang#8196) * Return infinity when calculating distance between different worlds * Throw a runtime error when calculating distance between different worlds * add world names to runtime error message suggestion made by sovdeeth Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> * fix runtime error message suggestion by sovdeeth * Update runtime error message Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> * Update ExprDistance.java
…iptLang#8196) * Return infinity when calculating distance between different worlds * Throw a runtime error when calculating distance between different worlds * add world names to runtime error message suggestion made by sovdeeth Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> * fix runtime error message suggestion by sovdeeth * Update runtime error message Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> * Update ExprDistance.java
Problem
Below is a code sample which checks whether some location is near the word origin
The problem is that this check fails (doesn't exit) when the location is in a different world, because the distance currently returns in that case. This kind of makes sense (the distance between two worlds doesn't exist), however it works inconsistently as seen in the above example.
Moreover you can invert the logic ( a > b is equivalent to !(a <= b) ), but end up with different behavior.
Solution
Changing the returned value from to infinity results in more consistent behavior.
Here infinity is larger than one, so the function exits correctly.
Additionally infinity better preserves some underlying mathematical properties which are discussed in the discord link under Related
Testing Completed
I tested that this returns the correct value by continuously printing the distance between myself and the world origin. It worked in the overworld and returned infinity when I went to the nether.
The unit tests all ran successfully (I ran the gradle quickTest action).
Supporting Information
This can change the behavior of existing skripts when they compare locations from different worlds, especially when they specifically account for the result being .
Completes: none
Related: https://discord.com/channels/135877399391764480/836220422223036467/1418191935310528517