I really don't understand "for each"

Get help using Construct 2

Post » Sat Jul 26, 2014 11:50 pm

I think you need to put FOR EACH as first event, and all other state events underneath it. Also you can put Every dt*2 Seconds above FOR each to not have it run every tick ( not needed ) . Also within each DistanceTraveled and Is events, add condition with your variables for example MoveClose = False. Try that.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sun Jul 27, 2014 12:12 am

See if this helps any. As you click each car, it updates it's text object independent of the others, and tracks it's own progress and which trigger to check next.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sun Jul 27, 2014 2:09 am

Are you able to extract a relevant portion of the capx? I can see it's pretty large.

Edit: never mind. see if attached capx helps. It's based on the code in your screenshot.
You do not have the required permissions to view the files attached to this post.
Last edited by codah on Sun Jul 27, 2014 6:45 am, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Jul 27, 2014 6:12 am

Thanks guys. I'll look at your examples first thing tomorrow. It's getting late. I'm going to get to the bottom of this yet! I've come too far to be slowed down by something so small.
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Post » Sun Jul 27, 2014 11:18 pm

@codah Hi, I was having a bit of trouble getting your capx to work with more than one enemyBox. This is the same problem I am having in my game. One enemy is fine, but more than one and it stops working. Let me know if you can get yours to register right for 2 or more enemyBoxes.

@blackhornet That capx is interesting. I am going to tweak it and try to adapt it to the kind of conditions my game will have and see if it works.

@megatronx I may have already tried putting the for each first. It's hard to say what combinations I've done since I've tried a dozen variations. I "think" I know what you are saying about adding another condition. I may be misunderstanding you though, but I think I know what you mean.

I'll hit this hard tomorrow and try to get it sorted one way or another!

For you guys wondering why I'm going through all this trouble, I'll share a bit about my game. It is a turn-based RPG roguelike. I currently have it set up on a tile system (the tiles follow you around) so you can only move a certain distance (like 200 pixels for example).

Here is a screenshot. I am NOT ready to start showing off my game yet, so this is the first public screenshot I have shown. Please ignore the Golden Axe sprites. I was about to start making my own character sprites when I got distracted with this step.

Image

I'm actually tempted to just make it so you can move any distance, and it will only use 1 turn. This would free up the movement a bit. I haven't decided yet though. The system I have is similar to the Civilization games where you take your turn, and the computer takes theirs. Each attack will cost one turn, and tasks like a health potion will also take one turn.

The heroes are working fine. This problem I am running into with multiple enemies is one of the major issues I've had so far. Once I get this taken care of, it's back to smooth sailing until I hit another major snag. I've been working at this game since December. Of course, I just got Construct 2 in October, so I'm still learning as I go which is why it's taking so long.
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Post » Mon Jul 28, 2014 12:57 am

hm yea that was slack of me. Will check it out when I get time but I'm sure BH & co will work it out before then :)
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jul 29, 2014 6:06 am

Well, I think what I'm trying to do is impossible.

I just keep running into infinite loops. You can't use a trigger once event with "for each." It will be ignored. Every time I actually do get both enemies to get their turn added, one always gets an infinite loop of turns added. Of course, if I don't use for each, then only one character actually gets the turn added. So, either way, I cannot get it to add up the enemies turns.

At this point, I am thinking of doing this part over and changing the system. I am only going to give each enemy 1 turn, not 3. This will enable to me use only green-arrow trigger once events such as "on pathfinding arrived" to trigger when the turn gets added. This will prevent any infinite loops.

I mean, it may work out fine. This system might even be more interesting. I don't know. What I do know is I can't take it anymore trying to get it to trigger once with a for each when the enemy pathfinds a certain distance. So, bollocks to it.

I have tried 100 combinations of trigger once events, functions, UIDs, boolean variables, giving different sprites the instance variables. No matter what, I end up in the same place; an infinite loop or nothing. I don't know what else there is to try. I don't feel like Construct 2 was made for what I'm trying to do.

So, tomorrow I'm going to rework the system a bit with only 1 turn per enemy/hero and see how it works out. It might even be better in the long run. Who knows.
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Previous

Return to How do I....?

Who is online

Users browsing this forum: beohs, tunepunk and 9 guests