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

Get help using Construct 2

Post » Fri May 01, 2015 12:39 am

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.
B
7
S
1
Posts: 39
Reputation: 511

Post » Fri May 01, 2015 2:05 am

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.
B
5
Posts: 13
Reputation: 251

Post » Fri May 01, 2015 2:24 am

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!
B
7
S
1
Posts: 39
Reputation: 511

Post » Fri May 01, 2015 2:29 am

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.
B
89
S
29
G
14
Posts: 1,159
Reputation: 15,038

Post » Fri May 01, 2015 2:30 am

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..
B
89
S
29
G
14
Posts: 1,159
Reputation: 15,038

Post » Fri May 01, 2015 2:32 am

jobel wrote: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.
B
7
S
1
Posts: 39
Reputation: 511

Post » Fri May 01, 2015 2:33 am

jobel wrote: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.
B
7
S
1
Posts: 39
Reputation: 511

Post » Fri May 01, 2015 3:36 am

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...
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 636
Reputation: 9,333

Post » Fri May 01, 2015 3:44 am

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.
B
7
S
1
Posts: 39
Reputation: 511

Post » Fri May 01, 2015 5:32 am

cool, sounds like an interesting game...
B
89
S
29
G
14
Posts: 1,159
Reputation: 15,038

Next

Return to How do I....?

Who is online

Users browsing this forum: Sparkz and 3 guests