How do I "pick by comparison" but only pick ONE at a time?

0 favourites
  • 12 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi,

    I'd like to use "pick by comparison" but not pick ALL instances that match the comparison, because I don't want each of the picks to do the same thing. I want to pick all of the matching picks but have them all different assignments.

    I tried the "Pick by Comparison" combined with a "Pick a random instance" but this seems to lead to crashes once in a while, I think. It doesn't feel like the best option.

    Anyone else have any ideas?

    Extra info: I have randomly generated "ores" that Mining ships are automatically attracted to. The way I have it set up, if a Mining ship is not currently in the process of mining, moving to mines, or returning a payload, it "searches" for available ores and if it finds one, it sets a course and moves towards it. I don't want all Miners to choose the same ore, I want each Miner to set a course to a different ore. I've gotten this to work with my set up described above, but it doesn't feel optimal. The Miners often have delayed reactions (with the nature of choosing "random" ships of the compared picks to give commands to) and sometimes the game crashes.

  • Use the instance ID (IID) to select them individually in the Pick by Comparison event, or assign each of the instances a unique variable (such as a string variable with some kind of unique name for each of them) and then pick based on that.

  • Forgive me if I'm misunderstanding, but I won't know what their IID is. The units are automatically spawned based on the environment. In game 1 there may be 20 miners, game 2 there may be 3 miners spawned, game 3 might have 45 miners.

    I would have to make a separate sub-event for the Pick by IID which would mean to be safe I'd need to make over 200+ sub-events for each IID? Or am I missing something?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • pick random will only pick 1 object. you can combine it with a compare using the Object event itself... no need to use the System event again.

  • the IIDs are just the objects number sequentially. 0-to how many you have..

    the UID is the unique number of the object in the entire game..

  • pick random will only pick 1 object. you can combine it with a compare using the Object event itself... no need to use the System event again.

    I've been using the pick random combined with the object event, but it doesn't seem to be the optimal way to do it. For example, if I have 40 miners doing various tasks, and lets say 23 of them are done mining and set to "Return payload".

    If i have

    Miner Instance Variable =Return Payload

    Pick Random Miner

    It WILL do everything as intended, just not as fluidly. Some miners may sit there waiting for a command because the game engine hasn't randomly picked it yet.

  • the IIDs are just the objects number sequentially. 0-to how many you have..

    the UID is the unique number of the object in the entire game..

    I know that, but how would I make the game pick an object without having to create 200+ subevents for every single IID? It seems wrong.

  • Just make your Miners dumber.. have an instance variable in the ore spawn that sets "in use" whenever the first Mining ship arrives. Then all the other Miners would stop and start searching again. You could have them only react to ores within a given range as well..

    just spitballing...

  • I found the main problem. Thanks for the ideas everyone.

    I looked at my conditions and realized the ordering of the conditions could be better, and also I had an "Every 1.0 seconds" condition in there too. That explains the delay in commands.

    In case someone googles this issue, here is what I find to be an ideal solution:

    Conditions:

    Miner = ReturnPayload

    Pick Random Miner

    This makes it so only objects taken with your first condition filtered out, resulting in choosing only ONE, instead of all.

  • cool, sounds like an interesting game...

  • cool, sounds like an interesting game...

    Thanks! It's fun to work on, so far.

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