Author Topic: Let's make a stable platform  (Read 40714 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Let's make a stable platform
« Reply #75 on: October 26, 2005, 07:58:30 PM »
Quote
Quote
OOps, .MaxVel should be rob(o).MaxVel   :redface:
so ...
 
if abs(rob(o).vx) > rob(o).MaxVel then rob(n).vx = sgn(rob(n).vx) * rob(o).MaxVel
if abs(rob(o).vy) > rob(o).MaxVel then rob(n).vy = sgn(rob(n).vy) * rob(o).MaxVel
 ?
And now my head exploded.

Post the whole function, and let me look at it.  Then I'll post a fix for it.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Let's make a stable platform
« Reply #76 on: October 26, 2005, 08:16:31 PM »
AH, okay, hold on a sec...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Let's make a stable platform
« Reply #77 on: October 26, 2005, 08:19:31 PM »
Code: [Select]
if abs(rob(o).vx) > rob(o).MaxVel then rob(o).vx = sgn(rob(o).vx) * rob(o).MaxVel
if abs(rob(o).vy) > rob(o).MaxVel then rob(o).vy = sgn(rob(o).vy) * rob(o).MaxVel

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

THat should do ya I think...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Let's make a stable platform
« Reply #78 on: October 26, 2005, 08:33:50 PM »
This code gives the bot information about what it's looking at.

refvelup is the relative velocity of the bot you're looking at along the direction you're looking.

if it's negative, than it's comming closer.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Let's make a stable platform
« Reply #79 on: October 27, 2005, 09:17:37 AM »
I finally managed to crash the program. Had to leave it running all night in debug mode to get it to break.

It is the same line of code that was reported earlier.

Code: [Select]
   While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
From reading the thread above I see that a lot of you may need a little direction in bug fixing/detection so I will go through this one step by step.

Now just saying that this line is a problem is not enough to actually debug this. You need to understand the reason why it goes wrong.

Here is the whole routine.

Code: [Select]
Public Function NextElement(ByRef DNA() As block, beginning As Integer, tipo As Integer, value As Integer) As Integer
  'takes the input for the first value in a gene and returns the position of the next statement
  'as defined by tipo and value
  Dim k As Integer
  Dim uboundarray As Long
  
  uboundarray = UBound(DNA())
  If DNA(uboundarray).tipo <> 4 And DNA(uboundarray).value <> 4 Then
    ReDim Preserve DNA(uboundarray + 1)
    DNA(uboundarray + 1).tipo = 4
    DNA(uboundarray + 1).value = 4
  End If
  k = beginning
  
  If beginning > 0 Then
    While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
      k = k + 1
    Wend
    If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
  Else 'beginning wasn't valid
    k = -1
  End If
  
  NextElement = k
End Function

First we have to figure out what is wrong. By hovering the mouse we can see what value is causing the trouble.
You very quickly find that hovering over the first part of the offending code line, it shows "DNA(k).tipo =<Subscript out of range>"
This means that the program is attempting to reference an array element that is outside of the allowed range.
Hold the mouse over k and you will see a value of 3

So how big is the DNA() array anyway? It should be bigger than 3 surely  :blink:  After all it is supposed to hold the entire DNA of the bot.

Go back up the code until you find a line that reads
Code: [Select]
uboundarray = UBound(DNA())Ubound is a function that returns the number of allowable elements in an array so the variable "uboundarray" should hold that value.

Hover the mouse over it and you will see 2  :blink:

Somehow the entire DNA of this robot is only 2 elements long.

We can fix this routine by adding a conditional that kicks it back out of the routine if the value of uboundarray is less than 3 but that only fixes a symptom.

What the heck is the actual problem?

We need to trace it back further than this. What other routine is calling this one?

To find out, click the binoculars on the VB toolbar and type in the name of this routine into the search box. Select "current project" and click "find next". If you keep pressing it, you will switch through every instance of this name in the entire code. You will quickly notive that "NextElement" is called from loads of different places. How to figure out which one called it?
It's actually quite easy. The call contains 4 elements, DNA, inizio and 2 digits. Simply hold the mouse over inizio in each of the calls until you see a value pop up. Only the routine that directly called it will do this so using this technique you can backtrack all the way through the code to find where the values initially came from.

More in a bit. I am still tracing this one myself right now.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Zelos

  • Bot Overlord
  • ****
  • Posts: 707
    • View Profile
Let's make a stable platform
« Reply #80 on: October 27, 2005, 09:27:27 AM »
I know it doesnt have to do with this, but ive tried .something and the vb says it dont work, how do you guys do that?
When I have the eclipse cannon under my control there is nothing that can stop me from ruling the world. And I wont stop there. I will never stop conquering worlds through the universe. All the worlds in the universe will belong to me. All the species in on them will be my slaves. THE ENIRE UNIVERSE WILL BELONG TO ME AND EVERYTHING IN IT :evil: AND THERE IS NOTHING ANYONE OF you CAN DO TO STOP ME. HAHAHAHAHAHAHAHA

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Let's make a stable platform
« Reply #81 on: October 27, 2005, 09:32:12 AM »
OK I traced this right back up to routine Updatepos where I found a veggie (robot # 22) with a DNA length of zero.

It isn't really possible to go back any further than this since we have no way of telling how this happened.

I guess there is no option other than to fix the routine where the bug showed up.

Go back there and change

Code: [Select]
If beginning > 0 Then
to

Code: [Select]
If beginning > 0 And beginning < uboundarray Then
That should stop it ever happening again. The routine will simply return the value of the last element in the array when called now. (2 that is)

After making this repair you can even restart the program by going to the "immediate" window and typing in "k=0" then hit enter and press the go arrow in the tool bar. The program will continue without fault.
« Last Edit: October 27, 2005, 09:39:05 AM by PurpleYouko »
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
Let's make a stable platform
« Reply #82 on: October 27, 2005, 09:33:32 AM »
Quote
I know it doesnt have to do with this, but ive tried .something and the vb says it dont work, how do you guys do that?

What did you try. We can't help much without specifics
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
Let's make a stable platform
« Reply #83 on: October 27, 2005, 09:36:22 AM »
Quote
btw ... I don't know that I have the tools you speak of in the VB6 I have.
will see about this 'binocular' thing next time I have a chance to play.

If you downloaded VB6.0 then you have these tools. This is the most basic stuff that comes with every VB installation. Nothing extra needed here.

You even get this stuff in a VBA macro code window in Excel, Word or any MS Office application
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
Let's make a stable platform
« Reply #84 on: October 27, 2005, 10:09:08 AM »
Quote
go back where?
to what modual?
First of all, did you understand my instructions about tracing where the call to a specific module comes from?

I want to work with you on this so that you understand but when I have tried moving in baby steps previously I was accused of talking down to people too much.

If I assume that people know stuff then I get complaints from people who don't but if I get too basic then I get complaints from people who know a bit more.

I's a bit of a los-lose situation if you know what I mean.

Perhaps I need to start a debugging for beginners article on the Wiki.
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
Let's make a stable platform
« Reply #85 on: October 27, 2005, 10:10:17 AM »
Quote
How to figure out which one called it?
It's actually quite easy. The call contains 4 elements, DNA, inizio and 2 digits. Simply hold the mouse over inizio in each of the calls until you see a value pop up. Only the routine that directly called it will do this so using this technique you can backtrack all the way through the code to find where the values initially came from.

More in a bit. I am still tracing this one myself right now.
 ^_^ Didn't know that.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Let's make a stable platform
« Reply #86 on: October 27, 2005, 10:12:36 AM »
Quote
Perhaps I need to start a debugging for beginners article on the Wiki.
Probably worth the effort.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Let's make a stable platform
« Reply #87 on: October 27, 2005, 10:16:45 AM »
Quote
Quote
How to figure out which one called it?
It's actually quite easy. The call contains 4 elements, DNA, inizio and 2 digits. Simply hold the mouse over inizio in each of the calls until you see a value pop up. Only the routine that directly called it will do this so using this technique you can backtrack all the way through the code to find where the values initially came from.

More in a bit. I am still tracing this one myself right now.
^_^ Didn't know that.
So how have you been debugging then?  :unsure:
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
Let's make a stable platform
« Reply #88 on: October 27, 2005, 10:19:06 AM »
Well, I'd led it crash.  Then I'd see the routine that crashed it...

And I'd put a fix in there ;)

Hehe.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Let's make a stable platform
« Reply #89 on: October 27, 2005, 10:23:55 AM »
Quote
You mean as you are now? Because you are.
Then you see my problem.

It is like being a lecturer when your class is a mix of kindergarteners and grad students. You can't possibly satisfy everybody with the level of the class.

I think I need to just start at basics and not worry about whether it's too low level for some.

I will see what I can achieve on the wiki
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D