For Each Object w/ Particular Value

Get help using Construct 2

Post » Tue Sep 03, 2013 1:21 am

I'm having an issue where I only want to call objects with a certain value in a for loop, however, I'm having huge issues.



So I only want to call walls with a areatype of areaselector (in this case, the number is 0)
It works great, except when there is more than one group of walls with a different area type. As soon as I add a second set of walls to clone, the walls get all messed up in size and position.

Is there an easy way to fix this or even an alternative? I briefly considered making a new family of walls for each room but that seems extremely tedious.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Tue Sep 03, 2013 1:55 am

when you filter/pick instances of a family, it doesn't automatically filter the individual objects that may or may not be in that family.

(To avoid confusion I'll refer to 'Walls' as 'Family' and 'Wall' as 'object')

So you may be correctly picking what Family instance.. but it's still ambiguous as to what Object instance you want..

hope that makes sense..

a way to pick the same object as the family you've alread picked is, for example

For each Family
   Object | Pick instance with UID: Family.UIDkeepee2013-09-03 01:56:18
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Tue Sep 03, 2013 2:38 am

[QUOTE=keepee] when you filter/pick instances of a family, it doesn't automatically filter the individual objects that may or may not be in that family.

(To avoid confusion I'll refer to 'Walls' as 'Family' and 'Wall' as 'object')

So you may be correctly picking what Family instance.. but it's still ambiguous as to what Object instance you want..

hope that makes sense..

a way to pick the same object as the family you've alread picked is, for example

For each Family
   Object | Pick instance with UID: Family.UID[/QUOTE]
Yeah it kind of makes sense, but it didn't work at all unfortunately. Here's what I did.



Just to make sure, I ran that same thing with all the walls deleted except for areatype 0 and it works as it should. Only when there are multiple area types is the problem happening.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Tue Sep 03, 2013 5:02 am

The purpose of the 'pick object instance with UID' was to pick the same object as the family you had filtered..

now you've put 'for each object', and then you try and pick an object with the UID of an unspecified family..

I think it'd help if I understand the context better..

now that i look at it more carefully..

is 'wall' a tiledbg within the 'walls' family? or is it a sprite that isn't part of the family?

also what's this for? are you swapping out editor placeholders for actual objects on start up?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Tue Sep 03, 2013 3:02 pm

@keepee

Yes, Wall is part of the Walls family.

Basically what I am trying to do is create rooms of walls that are off screen, and then clone those walls and re-position them in different areas in the game.

I don't really understand the problem with what I did as you explained. Do I put the for loop in the same spot as the UID check? I'm pretty sure I tried that.Sushin2013-09-03 15:03:42
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Tue Sep 03, 2013 6:38 pm

uh..sorry, i see now you are only using the family as a way to differentiate from the created wall object

In which case, your events in the original post actually look correct, so are you sure it's not a problem with the way you position it after creation? You could check if the wall have been created or not by using a text object to display wall.count

if they're not being created, it could still be a problem with the AreaSelector, or ZoneSelector... you can check these with a debug text object too.

If all that stuff is fine, try reshuffling the conditions so the 'For each' is before the variable check, it shouldn't make a difference, but I remember having to do this in some cases
like:

+On start of layout
+Zones | ZoneNumber = ZoneSelector
+For each Walls                     
+Walls | AreaType = AreaSelector      >Create object wall etckeepee2013-09-03 18:38:32
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Tue Sep 03, 2013 8:55 pm

[QUOTE=keepee] uh..sorry, i see now you are only using the family as a way to differentiate from the created wall object

In which case, your events in the original post actually look correct, so are you sure it's not a problem with the way you position it after creation? You could check if the wall have been created or not by using a text object to display wall.count

if they're not being created, it could still be a problem with the AreaSelector, or ZoneSelector... you can check these with a debug text object too.

If all that stuff is fine, try reshuffling the conditions so the 'For each' is before the variable check, it shouldn't make a difference, but I remember having to do this in some cases
like:

+On start of layout
+Zones | ZoneNumber = ZoneSelector
+For each Walls                     
+Walls | AreaType = AreaSelector      >Create object wall etc[/QUOTE]


It cant be a way I position it after creation, because like I said, if the only area that exists is area 0, it works perfectly. The Walls family has a value called Area Number that I change for which group of wall objects I want to spawn.

Area and Zone selector are set to 0 for now for testing purposes.

I did the count thing and it says the right amount of walls have been added. It looks like there are only 2 or 3 walls. I suspect they are stacked on top of each other so the X and Y values aren't really getting changed properly or something.

So far I have reshuffled the 3 conditions into every different order that makes sense. All together, and with the loop being the sub event, and with the wall and area selector being a subevent. It doesn't seem to make a difference...
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Tue Sep 03, 2013 10:53 pm

If this is the correct flow:
1) You want to select from family zones whatever matches ZoneNumber
2) You want to select from family walls whatever matches AreaType
3) You want to loop through the list of objects selected by 2) and create a new object for each with coordinates from the current zones and the current walls object

then this should have worked (basically your first try with just one small change):
+ on start of layout
++ Zones | ZoneNumber = ZoneSelector
++ Walls | AreaType = AreaSelector
+++ System | For each Walls
---> Create Wall at ...

If it doesn't then the coordinates you refer to seem to keep generic. The only thing that comes to my mind is that you have to make sure that the zones condition really only selects one object from zones. When applying zones.x and .y C2 has to have an explicit object to get the values from.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Wed Sep 04, 2013 1:58 am

@keepee
@tulamide

Well, It actually is starting to seem like the looping for that particular event is not causing me the huge problems. At least I think so. It actually seems to be the way I was indicating the X and Y values. Here's a picture of what I'm doing there:


And of my game layout


I added the for loop right where I'm assigning X and Y values and that fixed the original problem I'm having...but now only area 0 will recreate properly. Area 1 and 2 seem to have broken X and Y positions on the walls and my feeling is that it's part of the first "on start of layout" block.

I did your suggestion tulamide but the result didn't change from the picture above.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish, Yahoo [Bot] and 16 guests