-
December 13th, 2022, 17:45 #1
FGU lua math and function wierdness
I have two questions on how these things are possible, and how to resolve them (hopefully).
Question 1:
I have a lua file that does some math - then compares that to get a true false result....
Code:Debug.console(v.x*v.x + v.y*v.y); Debug.console(radius^2); Debug.console(v.x*v.x + v.y*v.y <= radius^2); return v.x*v.x + v.y*v.y <= radius^2;
Code:#49760288 #49760288 bFALSE
math.floor(v.x*v.x + v.y*v.y) <= math.floor(radius^2)
and also tried separating out each side into its own local variable and just doing "a <= b" - still it would appear the values printed were the same but would not come back true consistently (sometimes they would return true with same print values in other measurements of different map token distances - it was bizarre).
This seems less likely to happen on other maps with smaller grid sizes or with medium tokens. Any idea how to resolve this or why it happens?
Any ideas on what causes this or how to resolve it?
Question 2:
I have the following code:
Code:local nDistance = Token.getDistanceBetween(TokenInstanceA, TokenInstanceB); Debug.console(nDistance);
Code:#5
Here is screen shot of match (don't get me started on the tiny distance text - it seems to vary and I have no pattern on why)
DistanceMatch.jpg
And here is screen shot of it not matching when I move the token slightly further away
DistanceNotMatch.jpg
This can be easily duplicated on any map when you have grid locking and move a 1/2 square away.
Thus endeth my questions. I await enlightenment.Last edited by SilentRuin; December 13th, 2022 at 17:53.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 13th, 2022, 21:42 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 22,023
Question 1: No idea. My guess would be floating point differences; though I would expect the math.floor to address as you mentioned. Sort of curious that the numbers you are working with are generating numbers with whole numbers greater than 49m, which means that v.x and v.y are around 5000 each. As far as I know, the numbers in the Debug output aren't rounded, so it looks like you're already getting rounded numbers.
Question 2: Not sure without a specific example/extension showing what you are trying to do. Perhaps the event you are triggering on is happening before the actual token movement?
Regards,
JPG
-
December 13th, 2022, 22:18 #3
Yeah Question 1 is probably a lost cause - I just added a KLUDGE factor to the radius and force it to work. However, Question 2 if it worked would resolve anything outside of the expected range - except the half square issue.
To duplicate is super simple. Do the exact Token.getDistanceBetween call I made (or use the imagecontrol one its the same result) and simply see when you move one token next to another - it will be 5ft. And move it a 1/2 square away it will STILL be 5 ft. While the targeting indicator as shown in the images I gave shows it as 10ft. These are different values for a 1/2 square. There is something different between the Token.getDistanceBetween rounding (as its always to the nearest 5ft it appears) and whatever is used to do the target indicator distance. Only looking at your code (no access for me) would show you what that difference is. Any map/any extension that does this call and compares with the target indicator distance will show you the difference in nearest 5ft and they are different. Which is bad. I would expect the code function to do the same rounding up that the target indicator does.
And this has nothing to do with movement. The tokens are where they are shown - static.Last edited by SilentRuin; December 13th, 2022 at 22:21.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 16:16 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 22,023
For question #2, I just built an example extension, and it appears to work fine (attached). The extension triggers on token move, and spits out current position and position/distance of all targets. In the future, please provide a simple extension showing the issue with minimum number of steps; along with steps/pictures to show the exact steps to follow.
For question #1, I'm going to guess that the problem is that you are mixing operators. (i.e. x*x vs. radius^2) Try x*x and radius*radius instead. Otherwise, you'll need to provide the input values for any further investigation.
Regards,
JPG
-
December 14th, 2022, 17:18 #5
I did give details in the screen shots. First I had to add the 5E ruleset or your test .ext did not show up in my list (or I missed it). Then I brought up the same project and it gave the EXACT same results in your output as I showed you. As I moved - the distance stated it was #5 and for the first 1/2 square etc. as I described away from target (see screenshots again) the target pointer distance was 10ft. This is NOT the same thing. And your .ext showed the same thing I saw. Not sure what else to tell you. You have no screen shot showing your stuff. Here is mine when I move it 1/2 square away from target. Your stuff says #5 - the target line says 10ft - not the same.
Before Move
BeforeMove.jpg
After Move
AferMove.jpg
It's incorrect with your extension. The rounding off is different they should not be. As I said you'd have to look at your internal code to see why that is as I can't see that.
Yeah trying this /test with the number gives it working - and as I said even I get it working sometimes. As I worked around this with a KLUDGE factor added in I'm just going to chalk this one up to a mystery as I'm not sure how me assigning each side to its only value then doing the comparison would somehow mix an operator (that was one thing I stated I tried).Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 17:25 #6
But I am using extensions... (sigh) - one of them is doing this I bet.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 17:27 #7
Yep - not you guys my bad. I'll have to trial and error to see what is doing this. I have my suspicions.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 17:31 #8
There was a time I never used anyone's extensions but mine so I always knew what was going on and how to resolve it fast... though now I use 3 external ones.
Token Height... I'm coming for you!Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 17:36 #9
Problems? See; How to Report Issues, Bugs & Problems
On Licensing & Distributing Community Content
Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
Note, I am not a SmiteWorks employee or representative, I'm just a user like you.
-
December 14th, 2022, 17:41 #10Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks