Problem with iterating through points on the screen

Chicken is moving to random points in the room. I’m telling the game to keep finding points on the screen that meet all the requirements.
Once all the requirements are met, stop searching for points, and move chicken to that spot. When the chicken reaches that spot, find a new point and move chicken again.

This works really well until all points were searched through. After some time game doesn’t search for new points. Well, it actually does, but it goes to the 10th+ decimal of the last point so chicken basically stay at the last spot.

I’m guessing what happens is that all the points searched are stored in memory and they don’t get rewritten until I run the preview again.

So my question is, how do I tell the game to keep checking if previous points that didn’t meet requirements the first time, get checked again.

This is the method I use for checking for points

You’re not using RandomFloatInRange so there are no decimals.
When you use the change variable action, you overwrite the previous value, it is not stored in memory.
Is there a buffer for the pathfinding that you would be overloading? I don’t know, I would guess not. But do you really need to change the poor chicken’s destination 60 times per second? :sweat_smile:

You say the chicken stops moving after some time… seconds, minutes, hours?

When inspecting in debugger what is going with the x and y coordinates when chicken stops, every time I refreshed, the decimals would change. Prior to chicken stopping values are only integers.

Once the chicken spawns it should wonder around the room aimlessly while avoiding certain obstacles. And it is doing that.

The chicken’s destination is not changed 60 times per second, it is changed only once it arrives to the destination, until then pathfinding is doing its thing.

Since posting this I moved on to other things, but chicken was stopping around 10 seconds, give or take. Right now I previewed it and it seems it is working fine.

EDIT: the reason why I was worried was because in similar way I am spawning enemies, and sometimes it comes to the point where all of the enemies start spawning from the same point, instead of random new point every X seconds.

Ah, OK, then the pathfinding is more clever than I remember. :+1:
All good if the chicken fixed itself. :grin:

1 Like

I would move the Pathfinder move action outside of the while loop. The chicken won’t move if the target is inside an object that’s has an obstacle behavior but it will start to if the destination fails the other conditions. It’s using extra process time to check if the destination is valid twice(once by you and once by the pathfinder behavior). And I don’t know if quick repeated attemped moves has any side-effects.

Edit: I can’t tell if your snippet is main code or part of a function. I’m assuming you’re calling has reached destination at some point. If not you need to. It might need a different condition to trigger the very first move and a trigger once.

Hi. Thanks for the reply.

This is the whole function for chicken movement. I kinda snipped the code fast so it seems like Pathfinder is in the while loop but it is not. Chicken reaches destination and once it does, game check for new destination for chicken to move to.
As I said everything works fine at the moment, but I can’t be totally sure if it will continue working since I didn’t make any changes on this part. And I can’t reproduce this issue on demand.

While running the preview, the very same issue appears 1 out of 100 times when spawning enemies in different part of the code (as in; they start spawning at the same point over and over again). I am hesitant to close out this topic for now.

I think I got it. You’re checking a point but the whole object needs to move to the destination not just 1 point. So, a valid location would be the point plus the space around the chicken’s x,y. Think of it as a collision. A point next to a wall might seem valid until you try to actually move there. You need space for the whole object.

The Pathfinder can be tricky. Maybe after the move attempt check the can reach destination (I think that’s what it’s called)

If you try to move and it fails, will it ever trigger the reached destination I’m not at my PC to test. Maybe use that as the while condition.

I will try to it just to make sure. However, I somewhat doubt that’s the crux of the issue, since I am spawning enemies in a similar fashion later in the code, and I do not use Pathfinder there. Yet, the point of spawn gets stuck on rare occasions and enemies begin to spawn in the same location instead of random ones.

I checked Gdevelop. The condition is called path found. Sorry. I couldn’t remember. I don’t know how you’re adding the other objects.

I would check the path found after the move action. I like to add play sound as an action while debugging. I would add an event like [inverted] path found then play sound.

This is very interesting, and I hope you solve it because I would like to know what it was.

I have a project from another thread about customers and tables. It places an (x) when you touch or click an unreachable location. It’s a nice visual.

https://liluo.io/games/26b22c87-6c80-45b2-aa88-67c2cbdcdf70

1 Like

Sorry, I didn’t realize that other thread was a reply to yours

It’s okay I’m working on a problem right now I was thinking you should take a look at, heh heh heh.

1 Like