Multiple Instance Paths

Discussion in 'Programming' started by mcknightm, Aug 31, 2017.

  1. mcknightm

    mcknightm Member

    Joined:
    Apr 1, 2017
    Posts:
    3
    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.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,906
    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.
     
  3. mcknightm

    mcknightm Member

    Joined:
    Apr 1, 2017
    Posts:
    3
    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.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,906
    paths are not tied to objects, so yes they can have their own paths.
     
    Edmanbosch likes this.
  5. mcknightm

    mcknightm Member

    Joined:
    Apr 1, 2017
    Posts:
    3
    Thanks, TheouAegis. You've been an enormous help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice