Author Topic: Aim getting WAAAAAY too big  (Read 9975 times)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« on: October 27, 2005, 03:12:25 PM »
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: [Select]
 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)
You can find it in Updvars2 in the robots module.

The error occurs on line
Code: [Select]
.aim = .aim + (.mem(aimsx) - .mem(aimdx)) / 200
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.
« Last Edit: October 27, 2005, 03:13:01 PM by PurpleYouko »
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Ulciscor

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 401
    • View Profile
Aim getting WAAAAAY too big
« Reply #1 on: October 27, 2005, 03:17:42 PM »
Code: [Select]
mem(aimsx) = 1256 * Sgn(.mem(aimsx))
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?
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #2 on: October 27, 2005, 03:20:19 PM »
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]
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
Aim getting WAAAAAY too big
« Reply #3 on: October 27, 2005, 03:27:38 PM »
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 ;)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #4 on: October 27, 2005, 03:31:03 PM »
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.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Ulciscor

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 401
    • View Profile
Aim getting WAAAAAY too big
« Reply #5 on: October 27, 2005, 03:40:01 PM »
Omg! Might have just realised... it's the abs value of the condition, not the abs value of .aim used in the condition!

Please say I'm right, or I'll be well embarassed.   :redface:
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Aim getting WAAAAAY too big
« Reply #6 on: October 27, 2005, 03:43:53 PM »
That's what I got |)  (<-- LaForge from star trek smiely ;))

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #7 on: October 27, 2005, 03:46:47 PM »
HEHEHE

Partly

You ARE right that it is the abs value of the condition that is used to determine the value of .aimsx and .aimdx.

That isn't the error though.

Look very carefully at the condition. cough "brackets" cough
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Ulciscor

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 401
    • View Profile
Aim getting WAAAAAY too big
« Reply #8 on: October 27, 2005, 03:48:02 PM »
I'm guessing you need

Code: [Select]
(Abs(.mem(aimsx)) > 1256)
instead?
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #9 on: October 27, 2005, 03:48:18 PM »
here is a close up  :D

[span style=\'font-size:14pt;line-height:100%\']If Abs(.mem(aimsx) > 1256) Then [/span]
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
Aim getting WAAAAAY too big
« Reply #10 on: October 27, 2005, 03:48:35 PM »
Nope you lost me ;)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #11 on: October 27, 2005, 03:48:55 PM »
Quote
I'm guessing you need

Code: [Select]
(Abs(.mem(aimsx)) > 1256)
instead?
Nope. Sorry
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #12 on: October 27, 2005, 03:49:37 PM »
Quote
Nope you lost me ;)
Oh come on. It's obvious. What is that condition going to do?
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #13 on: October 27, 2005, 03:50:45 PM »
look at what is INSIDE the ABS() brackets.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Aim getting WAAAAAY too big
« Reply #14 on: October 27, 2005, 03:51:15 PM »
...that shouldn't be.....
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D