Multiple Instance Paths

M

mcknightm

Guest
NOOB saying hi. First post.

I have coding experience but new to GML.
I'm not requesting code snippets just general direction if possible.

Goal:
3 agents in each room, all use same sprites.

4 or more objects appear randomly in rooms which must be acquired.
- click on 1st object and agent 1 path finds its way to pickup
- click on 2nd object and agent 2 path finds its way to pickup
- click on 3rd object and agent 3 path finds its way to pickup
- click on 4th object and all agents busy then message "Wait for next agent"
agent 1 moves if available, agent 2 moves only if agent 1 is busy, agent 3 moves only if agents 1 and 2 are busy.

Question(s):
Use 3 agent objects or 1 object and utilize instances variables?
- can GM instances hold its own path?

I know I have a lot of learning in front of me, but I need to know if GM can perform these actions.
Any thoughts/direction is very appreciated. Thank you.

Pseudo-code saves puppies.
 

TheouAegis

Member
Make a ds_queue. Add all agents to it. When a target is clicked on, dequeue an agent. Use a for loop running from var i=ds_queue_size() while i>0, dequeue an agent, assign it the target, then break the loop. If i is 0, show your message that you need to wait for the next agent.

If you want the task to resume automatically, use a global variable to keep track of the desired target, or another queue if you want to enqueue multiple targets.

When an agent finishes its task, assign it to the agent queue and check if there are any tasks saved. If so, repeat the first part.
 
M

mcknightm

Guest
Make a ds_queue. Add all agents to it. When a target is clicked on, dequeue an agent. Use a for loop running from var i=ds_queue_size() while i>0, dequeue an agent, assign it the target, then break the loop. If i is 0, show your message that you need to wait for the next agent.

If you want the task to resume automatically, use a global variable to keep track of the desired target, or another queue if you want to enqueue multiple targets.

When an agent finishes its task, assign it to the agent queue and check if there are any tasks saved. If so, repeat the first part.
Thanks, TheouAegis.

I agree with your logic I'm pretty much on the same page. I'll nest loop thru targets and agents. Remove/add agents from queue as needed till targets done.
Thanks for the point at FIFO/LIFO, still new to GML.
I'll have to test if one objects instances(3 agents) can hold their own path.
 
Top