Advice on fixing a bug

Hi all,

I have almost finished my waypoint and race position system. The theory is sound, but I have an odd problem that I cannot visualise.

I have four cars, and they each race toward pre-defined nodes. When they get to a node a property increases by one and the cars look for the next node in a list. Also, the distance between nodes is also taken (if two cars share the same node) as well as how may laps have been done.

These measurements are added up into one property to simplify the sorting (the node number is an integer with the distance being a float: i.e. 2 + 0.6 = 2.6 b/u travelled). After each lap, the total amount of nodes is added to this value so the total race distance can be sorted (higher being further).

The trouble is, when the cars go past certain nodes the race positions go out of order but sort themselves out between nodes. Some nodes do this, others do not.

I am thinking it may be how the various distances are added. Can anyone see anything wrong?

Thanks for your patience,

Paul

Attachments

Steer_race_posi.blend (515 KB)

I read the other TD, but I have not figured out how to make an ordered list, so clear!

probably all script can be make in 3/4 line!:wink:


The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

partially solved , with a calculation of “subnode”

change this line:

own[‘float_distance’] = distance2 / 100 + node_count # nodes + distance
own[‘total_distance’] = len(nodes) * own[‘lap’] + own[‘float_distance’]

in to:

own[‘float_distance’] = distance2/(distance+distance2)
own[‘total_distance’] = own[‘lap’]*1000 + own[“node_count”]+ own[‘float_distance’]

but seem which remain those error
too many variable,avoidable, can hidden much bug! :wink:

Thanks Marco- I am pretty certain the problem lies in how the three distances are measured and put together somehow. It just seems strange as there is only one sort of the total_distance after three distances are combined (node, distance between nodes and total lap). some other things:

I think the Sort_Positions script is fine as it only sorts distances. I assume the sort() function is fast (I’m only comparing eight distances) and once the list is sorted this way it stays sorted and not reset somehow.

The logic blocks are not the problem. I experimented by raising the frequency from 0 to 5 to save some processing time but this does not seem to cause more problems.

I also think I should simplify things: ironically I thought I was simplifying by making the distance one value rather than making the sorting script do multiple loops!

“I also think I should simplify things: ironically I thought I was simplifying by making the distance one value rather than making the sorting script do multiple loops!”

not, I have not explained well,
the idea to compute the three distances is absolutely right!!! (good idea!!;))
multiple loop is more susceptible to errors
and is also more CPU intensive
the method is just

I meant the “style”, many variables are used, which already exist, there is a duplication of variables avoidable.

give an example:

##########
currentNode = nodes[node_count] # get next node
#duplication of —>>>own[“node_cout”]

oldNode = nodes[node_count -1 ] # get last node

distance = own.getDistanceTo(currentNode) # get distance to next node
#duplication of —>>> own[“distance”]
distance2 = own.getDistanceTo(oldNode) # get distance to last node
#duplication of —>>> own[“distance2”]
own[‘distance’] = distance

own[‘distance2’] = distance2

#################

and other… seem to me which make the script too complex !(my opinion)

anyway, the rest of the script looks fine!

the little error is due sure ,as say you, by the calculation of distance because , only when 2 cars is very near, make this little error(the position jump for 1 frame)…but where?

ie :

“lap” can be-> 0, 1000, 2000, 3000, …
“node_count” can be-> 0, 1, 2, 3, …
“float_distance” can be-> 0.0, 0.2, 0.8, 1.0

and total distance is a simply sum
not see margin of error, but is somewhere…

found a bug!!!

pratically was a this line (the distance must be recalculate immediately, when change nodes) :

with bug


distance = own.getDistanceTo(currentNode) # get distance to next node
distance2 = own.getDistanceTo(oldNode) # get distance to last node

if distance < 0.5: # high numbers lead to errors
    own['node_count']+=1 # add 1 to node_count (i.e. look for next node)

without bug


distance = own.getDistanceTo(currentNode) # get distance to next node
distance2 = own.getDistanceTo(oldNode) # get distance to last node

if distance < 0.5: # high numbers lead to errors
    own['node_count']+=1 # add 1 to node_count (i.e. look for next node)
    distance = own.getDistanceTo(currentNode) # get distance to next node
    distance2 = own.getDistanceTo(oldNode) # get distance to last node

:stuck_out_tongue:

version with module (less script)->

Attachments

Steer_race_posi3.blend (348 KB)

Wow, thanks Marco! You have some amazing Python skills going on there!

If I ever finish this game you will certainly get a major credit! :smiley:

thanks Rubber!! is only a bit of pratice with the lists! :wink:

you’ve already made the cars, with wheels, shock absorbers, steering, etc. … etc.?
(I do but I did crap only!)

Actually I am doing the reverse, doing all the code first and trying to avoid the trap of doing the easy stuff to begin with! I’ve always found scripting hard so I thought I should start there and not ignore it.

The game will be a mix of Einhander (a PS1 shoot-em up) with Wipeout (the racing game). Nearly all the code is finished now, I just have to start making the game models and textures, and fix any problems when the scripts run together.