NPC Individual Behavior

Get help using Construct 2

Post » Sun Mar 24, 2013 10:52 pm

Hello. I looked through the forums and was having a bit of trouble finding anything on the subject;

I am trying to figure out how to have two NPC's of the same image to follow the events in the list on their own, without being affected by the other's actions.

Example:

Miner 1 and Miner 2 go out to mine an asteroid.

The event states that once there is over or equal to 100 ore in the miner's hold, they should return to starbase and drop it off.

If Miner 1 finishes early, Miner 2 returns to starbase as well (This is what I don't want).

I would like them to complete their actions independently, without the hassle of making millions of other NPC's and matching event behaviors.

Hope this made sense.
B
4
Posts: 1
Reputation: 352

Post » Mon Mar 25, 2013 12:15 am

Hi im actually working on or just finished something similar to what you want. So maybe my solution can help you.

My initial idea was to use arrays to store whatever order each unit should do, but i find them very confusing in construct 2. And ran into some problems with them doing weird things, so dropped using them.

Instead i made a list object for each unit as they are created and added a "Unit_ID" variable that holds the UID of the unit it is linked to. This list can be seen as a queue of orders that the unit will perform.

So in your case it could be.

Miner.cargo_hold = 0 then Add to list "Go mine".

Miner.cargo_hold = 100 then Add to list "Return to base".

And so on.

Then you can make an event that check each miners order list.

So if miner1 have "Go mine" as the first item in the list. You can make an event that triggers if a unit have that job.

In my game two units cant work on the same thing at the time, so I added a function that make the units enter a "wait for job" state. It then goes through each unit one after another, to see if there are anything that needs to be done. And if its the case, that "job" gets locked to that unit.

Another way that can be useful as well, if you dont want to work with lists, is to add an Text variable to your miners called "Order" or whatever. And as default you set it to "None", if we assume that these miners uses fuel as well. An example could be:


Event 1:
Miner.order = "None" then Set Miner.order = "Go mine"
Miner.fuel = 100

Event 2:
Miner.order = "Go mine" then Miner fly nearest mining place.


etc etc.

Doing it by adding or updating the miners order each time they reach there goal. Will make it easier to keep track off them i think. Also it will make it easier to check you program if you can show the order of each unit as you test your program.

Assuming that suddenly one of your miners go crazy while testing, and you keep track of what order it have, will make it a lot easier to see where things might go wrong. For instant if a miner have order "Go mine", when it starts to act crazy. You can easily find the place in your program where it receive that order.

Also its a good idea to use "For each (ordered)" and then in expression add the <object>.UID, since UID of objects cant be the same, it will go through all objects of that type, one after another and will only pick one at the time. nimos1002013-03-25 00:17:28
B
40
S
10
G
2
Posts: 1,148
Reputation: 6,495

Post » Mon Mar 25, 2013 4:11 am

hmmm while we are on this topic Just curious can you some how create /spawn Sprite to be have set number but randomly generated. Such as if miner 1 2 3 dies then you want to spawn 4 5 6 and those dies then spawn 1 2 3 again ? Without having to place 6 sprite on layout of UID can you place one sprite on layout and attach UID to each spawn?
B
7
S
2
G
3
Posts: 58
Reputation: 2,284

Post » Mon Mar 25, 2013 4:43 am

i think you can use a container and spawn them so you wont have to place 6 sprites on your layout, only if you have an sprite for the animations and a sprite for the collitions. haifisch2013-03-25 04:44:51
B
17
S
2
G
2
Posts: 82
Reputation: 1,712


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 5 guests