Author Topic: Still get overflows!  (Read 5593 times)

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Still get overflows!
« on: October 28, 2005, 02:52:43 AM »
Da famous code:

rob(n).mem(refvelscalar) = CInt((CLng(rob(n).mem(refvelup)) ^ 2 + CLng(rob(n).mem(refveldx)) ^ 2) ^ 0.5) ' how fast is this robot moving compared to me?

Hov inf:

rob(n).mem(refvelscalar) = 30318

n = 189

refvelscalar = 695

CInt((CLng(rob(n).mem(refvelup))^2+CLng(rob(n).mem(refveldx... = <overflow>

CInt((CLng(rob(n).mem(refvelup)) = 31842

rob(n).mem(refvelup) = 31842

refvelup = 699

CLng(rob(n).mem(refveldx)) = -9348

refveldx = 697

The code suggested by Numsgil that should prevent values above 30000 (That's what it's all about, right?) had no effect:

temp = (rob(o).vx * Cos(rob(n).aim) + rob(o).vy * Sin(rob(n).aim) * -1) - rob(n).mem(velup)
  If Abs(temp) > 32000 Then temp = Sgn(temp) * 32000

 :bash:  Naughty Nums!
The internet is corrupt and controlled by criminally minded people.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Still get overflows!
« Reply #1 on: October 28, 2005, 09:09:27 AM »
Oh, I see why.

You have to apply that to the memory lcoations as well (which should never read that high, but let's just worry about the symptom at the moment.

Easiest way to fix it is to use a temporary long variable, or even a single.
Code: [Select]
dim temp as single

temp = (CLng(rob(n).mem(refvelup)) ^ 2 + CLng(rob(n).mem(refveldx)) ^ 2) ^ 0.5) ' how fast is this robot moving compared to me?

if abs(temp) > 32000 then temp = sgn(temp) * 32000

rob(n).mem(refvelscalar) = temp

replaces the single line you gave at the start of the code.

Now if that[ overflows, I'll eat my hat ;)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Still get overflows!
« Reply #2 on: October 28, 2005, 09:23:16 AM »
I would use a double instead, just to be sure.

Longs can only hold integer values so that would be kinda pointless.

How the heck is it getting so big anyway?
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Still get overflows!
« Reply #3 on: October 28, 2005, 09:27:21 AM »
I don't know.  The routines for actual movement are spread all over.  Part of what I did for 2.4 was put all the routines for updating velocity and position in one place, and have all the others modify a vector for impulse.

Then you just do:

.vel = .vel + Impulse / mass
and:
.pos = .pos + .vel

(more or less) all at once, and bounds check them.  Much safer and cleaner.

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Still get overflows!
« Reply #4 on: October 28, 2005, 10:24:09 AM »
I replaced the following code:

Dim temp As Long
  temp = (rob(o).vx * Cos(rob(n).aim) + rob(o).vy * Sin(rob(n).aim) * -1) - rob(n).mem(velup)
  If Abs(temp) > 32000 Then temp = Sgn(temp) * 32000

...with the code you mensioned above. Look at the picture what happens.
The internet is corrupt and controlled by criminally minded people.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Still get overflows!
« Reply #5 on: October 28, 2005, 10:29:11 AM »
You have too many parenthesis in that statement.

Remove the first opening parenthesis and it should run
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Still get overflows!
« Reply #6 on: October 28, 2005, 10:33:24 AM »
If you mean removing the parentesis at (CLng close to the beginning of the line it will give a compile error at ^ 2).

If I remove the pasentesis at ^ 0.5) instead I don't get the error, but what if that will mess up the code?

I'll give it a try.
« Last Edit: October 28, 2005, 10:40:38 AM by Testlund »
The internet is corrupt and controlled by criminally minded people.

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Still get overflows!
« Reply #7 on: October 28, 2005, 10:57:40 AM »
Time to eat your hat nums!

Got run-time error 6 overflow again.

Code:

rob(n).mem(refvelup) = (rob(o).vx * Cos(rob(n).aim) + rob(o).vy * Sin(rob(n).aim) * -1) - rob(n).mem(velup)

Do I have to type in the hovering info again?  :sleep:
The internet is corrupt and controlled by criminally minded people.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Still get overflows!
« Reply #8 on: October 28, 2005, 11:10:41 AM »
temp=(CLng(rob(n).mem(refvelup)) ^ 2 + CLng(rob(n).mem(refveldx)) ^ 2) ^ 0.5)

The highlighted parenthesis looks wrong since it isn't normal to have one before the Clng function.
However I can see whay removal of it would cause a problem further into the code.

Anyway, if my fix posted in the other thread is right then this is entirely beside the point anyway since the problem has been fixed at the source rather than at the symptom.

And again the million dollar question.

Are you running with corpses enabled?
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Still get overflows!
« Reply #9 on: October 28, 2005, 11:29:22 AM »
Yup. I guess we're having to topics about the same problem here, don't we. Maybe it's better to delete this one.
The internet is corrupt and controlled by criminally minded people.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Still get overflows!
« Reply #10 on: October 28, 2005, 12:05:12 PM »
Quote
Time to eat your hat nums!

Got run-time error 6 overflow again.

Code:

rob(n).mem(refvelup) = (rob(o).vx * Cos(rob(n).aim) + rob(o).vy * Sin(rob(n).aim) * -1) - rob(n).mem(velup)

Do I have to type in the hovering info again?  :sleep:
that line is supposed to be rewritten.  Replace it with the code I gave above (I should have been more explicit) instead of just placing the code above before it.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Still get overflows!
« Reply #11 on: November 15, 2005, 10:21:14 AM »
velocity bugs all fixed now.  B)

Moved to "solved Bugs"
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D