Code center > Solved Bugs

Still get overflows!

(1/3) > >>

Testlund:
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!

Numsgil:
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: ---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
--- End code ---

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

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

PurpleYouko:
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?

Numsgil:
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.

Testlund:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version