0 Favourites

Multiple Instances, Independent Behavior [Solved]

  • My question is, how is it that I can have multiple instances of a sprite with AI that will behave independently from each other?

    I have Drones in my game for mining asteroids. They have an instance variable for Cargo, and when it is below 1,000 they target asteroids to mine. Once Cargo exceeds 1,000 they return to the nearest Space Station to unload.

    The problem I am running into is that as soon as one Drone wants to return, suddenly all Drones want to return. This problem is the result of me using Turret behavior for Drones to target either asteroids or stations, when one gets reprogrammed, they all get reprogrammed.

    I could conceivably recreate turret behavior from scratch in a way that avoids this issue, but I would continue to run into similar issues in other areas of AI.

    I could make many, many clones of the "Drone" sprite which all have their own unique events to program their AI, but this would be incredibly tedious especially since I plan on having a wide variety of Drones for performing different tasks.

    Reading that I have done on this topic suggests that independent behavior among multiple instances could be accomplished with lists or arrays, but no articles or videos offered thorough explanations of how that actually works.

  • Hi, are you adding a 2nd condition during re-targeting where you require that the drone has >1000 cargo? Normally if you add this requirement then any ACTION that you specify will only happen to the specific drone who has met this requirement in that specific moment.

    Worst case give the drones another instance variable called I_AM_FULL = 0

    and then require drones to have I_AM_FULL = 1 during re-targeting

    You can make the I_AM_FULL = 0 become I_AM_FULL = 1 using a TRIGGER ONCE action when the drone has 1000+ cargo

    And remember to again set I_AM_FULL = 0 after re-targeting

  • No it's only one condition, here I'll show you.

    But I'll definitely try your idea, using a second instance variable alongside Trigger Once and get back to you with how it plays out.

  • Hi, are you adding a 2nd condition during re-targeting where you require that the drone has >1000 cargo? Normally if you add this requirement then any ACTION that you specify will only happen to the specific drone who has met this requirement in that specific moment.

    Worst case give the drones another instance variable called I_AM_FULL = 0

    and then require drones to have I_AM_FULL = 1 during re-targeting

    You can make the I_AM_FULL = 0 become I_AM_FULL = 1 using a TRIGGER ONCE action when the drone has 1000+ cargo

    And remember to again set I_AM_FULL = 0 after re-targeting

    I tried implementing your idea but it isn't changing their behavior. I thought maybe I was misunderstanding how you meant it to be implemented so I tried quite a lot of experimentation but haven't made any progress.

    Could you show me an example how this would work?

  • This is a picking issue. Try adding a "For Each Drone", then checking the cargo as subevents. It should clear up the problem.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • This is a picking issue. Try adding a "For Each Drone", then checking the cargo as subevents. It should clear up the problem.

    I think I understand the problem and I think that this should work, but it isn't changing their behavior either. Again, I tried experimenting and implementing it in different ways but nothing worked.

  • I'm beginning to think the issue is with the Turret Behavior. I think that maybe it can not be instance specific, that if I change anything about the Turret Behavior for one instance it will change the behavior for all instances regardless of how that change occurs?

  • Case Closed

    I was correct in my assumption that the Turret Behavior is incapable of having Instance Specific conditions, so I used an alternative targeting method and now everything is working as it should.

    I appreciate everyone's input on this, although it ended up being an old "HomingMissiles.capx" example provided by Yann that gave me the solution I needed. It was from this thread:

    And thanks to cjbruce's input about the For Each condition, the Drones will not all target the same Asteroid/SpaceStation

    Here is a screencap of the targeting method, in case it can be of use to anyone.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)