Linking a 'command' to an AI unit based on sprite

Get help using Construct 2

Post » Sat Feb 07, 2015 12:02 am

Hello, I hope someone will be able to help me.

I'm making a game with one player controlled unit, and many tiny units that can be issued commands via keyboard + mouse clicks. I have no problem with this so far.

The section that works properly:
Right click, create a "Collection Area" sprite. One random unit that matches the requirements through instance variables (is not busy, is of a valid type, etc) is then issued the command to go to the Collection Area marked by the sprite, and perform his collection duties. He picks up an object, brings it to his destination, drops it off, and then goes back to the collection area, and repeats. This all works great.

The issue I have is, I want to be able to 'cancel' specific Collection Area routes. I have the events based on an "On Creation of Collection Area" Sprite, so when the Sprite is deleted, nothing happens. I can't just have a 'send all' command to all the units, because I need each unit to be directly linked to each Collection Area.

Essentially, I want each Collection Area to be 'linked' to the unit that is carrying out that command. When that specific Collection Area sprite is destroyed/canceled, I want the unit that was working on that to be notified he can go back to his normal duties.



Any ideas?
B
7
S
1
Posts: 39
Reputation: 511

Post » Sat Feb 07, 2015 12:20 am

Here is a go at it:

1) create a instance variable for each "collection" area.
workerUse = 0

2)Create a instance variable for the worker:
workerBusy = 0

3) When a worker starts to use the "collection" area.
System > set value > collectionArea.workerUse = 1
System > set value > worker.workerBusy = 1

4) On collection area destory:
System > set value > worker.workerBusy = 0
System > set value > collectionArea.workerUse = 0

5)Have an event that tells the worker what do(move,fight,harvest) based off what worker.workerBusy is set too.. 1=fight 2=harvest 3=return to path etc...
B
11
S
2
Posts: 40
Reputation: 680

Post » Sat Feb 07, 2015 5:45 am

CigarOfSinatra wrote:Here is a go at it:

1) create a instance variable for each "collection" area.
workerUse = 0

2)Create a instance variable for the worker:
workerBusy = 0

3) When a worker starts to use the "collection" area.
System > set value > collectionArea.workerUse = 1
System > set value > worker.workerBusy = 1

4) On collection area destory:
System > set value > worker.workerBusy = 0
System > set value > collectionArea.workerUse = 0

5)Have an event that tells the worker what do(move,fight,harvest) based off what worker.workerBusy is set too.. 1=fight 2=harvest 3=return to path etc...



I actually have a similar set up right now! However, on step 4, if I were to set value to worker.workerBusy = 0, all Workers (since there will be multiple) will be set to stop working.

I actually came up with an idea of perhaps using a For Each Collection Area condition combined with a "Pick Worker" condition to handle the collection zones, and then separately have a "dead mans switch" so when the above event stops, it will automatically change back to default actions...

Unless you or anyone else has come up with a better idea!

Thank you for putting a good effort in, I've actually been trying to figure this out for a few hours now..



edit: Figured out a fix-- basically links a collection area with the worker.

Saw a nifty trick here
http(removethis)://www.scirra.com/tutorials/361/understanding-uid-iid-health-cards-and-rocket-smoke-trail
Created a "number" instance variable called "parent" and just referred to the UID whenever I needed to pick it.
B
7
S
1
Posts: 39
Reputation: 511

Post » Sat Feb 07, 2015 10:18 pm

Ah good! Glad you found a fix! That was a fun mental problem to think about!
B
11
S
2
Posts: 40
Reputation: 680


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests