Code center > Solved Bugs
Aim getting WAAAAAY too big
PurpleYouko:
I found a new one.
A really frickin stupid one too.
It should never exist. Whoever programmed this bit of code should change his name to Richard Head.
It was quite possibly me that did it :redface:
Here is the code
--- Code: --- If Abs(.mem(aimsx) > 1256) Then .mem(aimsx) = 1256 * Sgn(.mem(aimsx)) 'new crash fix?
If Abs(.mem(aimdx) > 1256) Then .mem(aimdx) = 1256 * Sgn(.mem(aimdx))
If .mem(setaim) <> 32000 Then
While .mem(setaim) > 1256
.mem(setaim) = .mem(setaim) - 1256
Wend
While .mem(setaim) < 0
.mem(setaim) = .mem(setaim) + 1256
Wend
.aim = .mem(setaim) / 200
.mem(setaim) = 32000
End If
.aim = .aim + (.mem(aimsx) - .mem(aimdx)) / 200
If .aim > 2 * pi Then .aim = .aim - 2 * pi
If .aim < 0 Then .aim = 2 * pi + .aim
.aimx = Cos(.aim)
.aimy = Sin(.aim)
--- End code ---
You can find it in Updvars2 in the robots module.
The error occurs on line
--- Code: ---.aim = .aim + (.mem(aimsx) - .mem(aimdx)) / 200
--- End code ---
Holding the mouse over ".mem(aimsx)" gives -32000
Holding the mouse over ".mem(aimdx)" gives 1256
This is obviously going to push .aim beyond the 32768 limit and give us an overflow.
I thought I had fixed this ages ago by limiting .aim to a magnitude of 1256. The code to do it is right up there in this chunk of code.
See if you can spot the stupid ass mistake in it.
Ulciscor:
--- Code: ---mem(aimsx) = 1256 * Sgn(.mem(aimsx))
--- End code ---
Does this do what I think it does?
If the absolute value of .aim is > 1256 then multiply it by the sign? Won't you always end up with the absolute value of what .aim was to begin with?
PurpleYouko:
No you will end up with a value of 1256 multiplied by the original sign of the value.
Example
-2598 will become -1256
6589 will become 1256
All it does is to cap the value without changing the sign.
[hint]Look at the condition before this[/hint]
Numsgil:
I don't think I touched the aiming controls in 2.37.4 (totally code raped them in 2.4 however ;))
DL 2.4 and find where I handle turning (I thinks its called SetAImFUnc or something like that, I'd have to look to be sure) and see how I did it, while we're cracking down on bugs ;)
PurpleYouko:
I have already fixed this BTW. I just want to see if anybody else can see the glaringly obvious cock up before I tell them what it is.
I am pretty sure this is code that I added myself so I'm the one who did the dirty deed.
Navigation
[0] Message Index
[#] Next page
Go to full version