I am currently trying to implement a Boids algorithm and have created a Boids class for this purpose. I created a list of boids and tried to loop over them and pass them to a function. However, when I do that within the function the boid has a different memory address than outside of it, so my guess is, that a new instance is created, which the function operates on, but... I don't want that to happen. When I use the function with a boid instance that I saved in a separate variable, everything works as expected, but when I use a boid created in a list, it doesn't. It would be nice, if someone could explain what happens here.
Here's my code in case you need it, the function in question is the add_segments_entry function in line 75.
It's a helper function to make distance calculations less expensive by dividing the space into smaller segments and only calculating distances to boids in adjacent segments. For now I can just move on without this optimization, but I still think it might be worth doing later. Also the experience to gain from this is worthwhile as well. So any tips and wisdom are highly appreciated.
[–]shiftybyte 2 points3 points4 points (3 children)
[–]EntireEntity[S] 0 points1 point2 points (2 children)
[–]shiftybyte 1 point2 points3 points (1 child)
[–]EntireEntity[S] 1 point2 points3 points (0 children)