[Solved] Help with the logic of choosing an empty table

In my cafe game I’d like to create customers that spawn at the doorway at regular intervals, determine if there is an empty table, and move to the empty table. Well maybe I was just tired after work last night but I could just not figure out the logic for them to choose an empty table and move to it. I was using the pathfinding behavior and all my attempts resulted in somewhat hilarious scenes where the spawned customers would either pile up on the same table, cower in the middle of the room unsure of what to do, pile up at the door because my logic was telling them that the table they just picked was now taken, etc. How should I go about tackling this problem?

That sounds interesting. Can you post a screenshot or 2 of the game. It’s tough to offer suggestions without a clear picture of what you’re trying yo do.

Thanks I hope it will be interesting. I’ll throw some screenshots up when I get home. There isn’t much so far because I haven’t figured out the logic of selecting table. So I think I have so far, customer spawns at door and goes to a table, another customer spawns 5 seconds later and goes to the same tablle.

What I want is, customer spawns at door. It checks for empty tables. If there is not one it leaves in a huff. If there are empty tables it randomly selects one and moves toward it. Meanwhile another customer spawning will not select this table because a customer is either already at it or heading toward it.

I tried using the pathfinding behavior. I don’t know why but it was useless. It might be my code, a limitation or a bug. Some “customers” just refused to move until I ramped the grid up to 10,000 but then the objects just went straight to the table. I might experiment later to see if it was my approach.

I replaced the pathfinding code with a tween and it worked perfectly other than customers walked thru tables. I set the tween duration to (distance between customer and table) * 5 So, they moved at the same speed no matter their distance.

Edit: I rotated the objects at the end of the tween just to make sure the tween was being removed. I have trouble figuring out sometimes when you need to use for each instance.

ScreenRecorderProject45

I added: if customer was clicked, customer in collision with table. table.Variable(available)=true, and then the same tween to the opposite corner to move the customer to the exit. I guess you could tween them to a cashier first and then to the exit. Once the tables Boolean is set to true, the table becomes available again.

2 Likes

This is awesome, it looks great. When I get home i’ll be able to play with it but it looks perfect and a lot better than what I was coming up with. Thanks so much, this is only my second game so still have a lot to learn I guess.

1 Like

I figured out why my pathfinding didn’t work. I didn’t leave enough room. To test the pathfinding, I created this project. It completely ignores the tables. When you press the mouse, it adds a customer. If the path is reachable, it moves the customer otherwise it deletes the customer and adds a noPath object at mouse location. If you click a customer it will return to 50,50 and then be deleted.

I drew the path to get a better understanding of what was happening. The object color decides the color of the line. Since paths may overlap, each customer might not have its own path color.

Zip of the project:
doug13579/gdevelop-pathfinder-diner: gdevelop example using pathfinder to add customers with mouse and make them leave with a click (github.com)

online playable version:

1 Like

I’m at home working on this now, I’m quite interested to give this a look, thank you very much.
Actually I was revising to use the tween example you showed but I think you’re on to something with the new pathfinding example you created.

1 Like

The confusing part for me is that the pathfinder doesn’t use the collision mask. A way around this is to use 2 sprites. A small one for pathfinding and another for the table without pathfinding. You can cover the sprite or just use the hide action. It doesn’t need to be visible to work. If you place the mask object in designer mode then a “for each object” could add a table object at the position of each pathfinder.

1 Like

I was thinking something along that line. Your example gave me several ideas and I was up working on it a little later than I should have been. I don’t think I was clearly grasping what was occuring in the pathfinding behavior but it’s starting to click and now I have a few more things I want to try out. I added a menu board destination and trying to implement a timer. I probably should mark this topic as closed because I’m confident you’ve steered me in the right direction and I’m happy with the result so far, a few more tweaks to iron some things out. Thanks so much for all your help and making this so much clearer.

1 Like

You’re welcome. I’m a very visual person. And drawing the path really helps see what’s happening. Good luck. Now, go to sleep.

1 Like