How do I have a minion do a task?

Get help using Construct 2

Post » Thu Oct 13, 2016 10:58 pm

Trying to get a minion to chop down a tree. Clicking on the tree marks it to be chopped down. The tree has 50 hp. The loop crashes the browser no matter what conditions I put in. No idea what I'm doing wrong.

www -dot- cazualnoob -dot- com/web-games/ (second game file)
B
7
S
2
Posts: 28
Reputation: 483

Post » Thu Oct 13, 2016 11:07 pm

You can't use a while loop - that is what is causing the crash. Just flag that "arrived" occurred, and move the 1-second code to the top event level, and check if the "arrived" flag is true.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Fri Oct 14, 2016 2:22 pm

Wow, thanks. I was over-complicating that a lot.

So, can characters effect and/or be affected by a background tilemap? Like slow down characters going through mud? Or would I need to make sprites for that?
B
7
S
2
Posts: 28
Reputation: 483

Post » Fri Oct 14, 2016 2:53 pm

Glitchster wrote:So, can characters effect and/or be affected by a background tilemap? Like slow down characters going through mud? Or would I need to make sprites for that?


You should be able to using:
Tilemap conditions

Compare tile at
Compare the tile ID at a position in the tilemap.

https://www.scirra.com/manual/172/tilemap


Although, that could add in a lot of checks every tick
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Fri Oct 14, 2016 9:09 pm

www -dot- cazualnoob -dot- com/web-games/ (second game file)

well... my little minion will only chop 3 or 4 trees then I can't make him do anymore - no idea why.
B
7
S
2
Posts: 28
Reputation: 483

Post » Sat Oct 15, 2016 2:02 pm

Glitchster wrote:www -dot- cazualnoob -dot- com/web-games/ (second game file)

well... my little minion will only chop 3 or 4 trees then I can't make him do anymore - no idea why.


Long story short, I'm pretty sure it is the "trigger only once" on the chop=1 condition. So if you click two trees they will both have chop=1 and once one tree is chopped the event won't fire again.

And just to note, this isn't me complaining but for your benefit on getting help in the future—your project is pretty messy. A lot of disabled events and events that do nothing. It is asking a lot to post your whole capx and ask for people to read through it all. Try putting events in groups, using comments, and using the bookmark on the events you want people to trouble shoot. Just saying it took a while for me to even find the part to trouble shoot and I almost said screw it. (but I didn't :D )
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Wed Oct 19, 2016 10:06 pm

badmoodtaylor wrote:
Glitchster wrote:www -dot- cazualnoob -dot- com/web-games/ (second game file)

well... my little minion will only chop 3 or 4 trees then I can't make him do anymore - no idea why.


Long story short, I'm pretty sure it is the "trigger only once" on the chop=1 condition. So if you click two trees they will both have chop=1 and once one tree is chopped the event won't fire again.

And just to note, this isn't me complaining but for your benefit on getting help in the future—your project is pretty messy. A lot of disabled events and events that do nothing. It is asking a lot to post your whole capx and ask for people to read through it all. Try putting events in groups, using comments, and using the bookmark on the events you want people to trouble shoot. Just saying it took a while for me to even find the part to trouble shoot and I almost said screw it. (but I didn't :D )



Yea, it's a mess. I'm saving some code for later which is why it's disabled. I didn't think it would be a problem finding the section I was working on, but I'll figure out the bookmarking feature and use it from now on.

Still have no idea what I'm doing, but I'm sure I'm going to have to change all those sprites into tilemaps and figure out a way to limit the ones marked. Then figure out a way to, like you said, take out the trigger once to make him find the closest marked tree, chop it down, then find the next marked closest tree.

It's gunna take me a lot of time to figure it out.
B
7
S
2
Posts: 28
Reputation: 483

Post » Thu Oct 20, 2016 12:48 am

I marked 2 groups "Tree" and "Chop".

First problem I can't figure out is why when you click a tree the second time it doesn't unmark it for chopping down. ... well now it doesn't change the tile to the tree with the x on it anymore...

Second problem is I can't get him to chop down the tree that he's next to.

I don't really want to limit how many he can cut down. I just want him to go to the closest one and stay there until it's down then find the next closest one that is marked.

I uploaded the capx file to my server - same spot if anyone wants to check it out.
B
7
S
2
Posts: 28
Reputation: 483

Post » Thu Oct 20, 2016 4:39 am

Glitchster wrote:...I just want him to go to the closest one and stay there until it's down then find the next closest one that is marked...


That would have been good to know when giving advice on your previous comments. I figured you still wanted it to be point and click so gave advice on that.

Either way, I would make the minion into a state-machine. Something like idle->find->move->arrived->chopped->idle. You would have an instance variable for "state".

So:
if state=idle then set state to find and find path to closest tree
on path found set state to move and move along path.
on arrived set state to chopping and set timer
on timer destroy tree, add to wood variable, and set state to idle
(thus, since idle again would find closest tree and start the cycle over again)

So with those events I left out arrived but depends on circumstances of what you need. Shouldn't really be too hard if you understand state-machines and can get that cycle down
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Thu Oct 20, 2016 5:42 pm

Thanks for your advice, it worked like a charm. I'm starting to get a lot better idea of how construct 2 flows. If you want to see it in action, I uploaded the capx.

In the sake of the forum and future searchers:
Image
B
7
S
2
Posts: 28
Reputation: 483

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Google [Bot] and 32 guests