"For Each" Expression and Overlapping Objects

Get help using Construct 2

Post » Fri Jun 13, 2014 9:45 am

Hoping someone can shed some light on where I'm going wrong here :)

In a nutshell: I'm making a city-building game, and when players construct housing blocks next to each other I'd like to add a bonus to the number of people they can house. By default, a housing block adds space for 10 units of population. Adjacent housing blocks should increase that by an additional 5 units. So if you build three housing blocks in a row, the centre block will provide 20 units, and the outside blocks will provide 15 units each.

What I've tried: I'm running this event sheet section under a "System: Every 1.0 Seconds" check, with the idea that the game will regularly be checking each housing block to see if it has become eligible for bonus population, but without running the checks every single tick:

Image

The yellow SlotHousingBonus object is created on top of each SlotHousing object (and will be invisible). I tried this because asking the event to check if each SlotHousing was overlapping another SlotHousing at an offset wasn't working. This attempt isn't working either, and I'm not sure why. Population stays at 10 units for each block instead of adding the bonus amounts as well.

Does the "For Each Object" command not work this way? Is there a mistake I'm making in the checks? I can't figure this one out myself :lol:

Many thanks for reading.
B
15
S
8
G
7
Posts: 255
Reputation: 5,368

Post » Fri Jun 13, 2014 10:45 am

My guess would be to not use collisions checks for that for 2 reasons:

First it is not easy to do like that
Second: you would be better off trying to make an array to reference each building placement in a grid when needed, as well as referencing the bonus for each case of the grid, which will be better performances wise, and also will let you have more control over that


But if you want to reallu go with what you have made, make sure that slothousing bonus isn t too wide (if it is 48 on 48, it will actually overlap at the border I think)

Also the for each is redundant
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Fri Jun 13, 2014 3:00 pm

Thanks for the reply :)

They're 48x48 objects, so figured an overlap check at self.X -/+ 48 would work.

I've tried changing it to an overlap check of -/+24, tried getting rid of the "for each" part, and tried checking for housing overlapping housing again rather than overlapping the additional yellow box. Still not working and I have no idea why :cry: I don't think there's anything wrong with the event setup. There must be, but I'm not sure what :?

As for arrays, I've never understood them. I'm a very visual person, good with art, terrible with numbers. I can puzzle things out with collision checks because it's a much more visual process. Arrays... just confuse the hell out of me :D

If anyone has an idea about why this collision check is failing, I'd love to hear from you. Even if it's just a complete guess!

Many thanks!
B
15
S
8
G
7
Posts: 255
Reputation: 5,368

Post » Fri Jun 13, 2014 3:12 pm

Here's a quick working example. Since you have a license I've used families as it will save you having to create the "slothousingbonus" object for every "housing" object.

checksatoffset.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Fri Jun 13, 2014 4:18 pm

Thank you SO much! Using families solved the problem :D

Added bonus - I had no idea families had been added to C2! I was still patiently waiting, expecting them to one day pop up in the same place they were in Classic, somewhere around C2's containers section in the left-hand panel :lol:
B
15
S
8
G
7
Posts: 255
Reputation: 5,368

Post » Fri Jun 13, 2014 4:29 pm

-Silver- wrote:Thank you SO much! Using families solved the problem :D

Added bonus - I had no idea families had been added to C2! I was still patiently waiting, expecting them to one day pop up in the same place they were in Classic, somewhere around C2's containers section in the left-hand panel :lol:


I suggest you to read the manual more often: https://www.scirra.com/manual/1/construct-2

not saying that with a mean spirit, just families are I think here since.. 2012? ( https://www.scirra.com/construct2/releases/r75 )
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Fri Jun 13, 2014 4:35 pm

Aphrodite wrote:
-Silver- wrote:Thank you SO much! Using families solved the problem :D

Added bonus - I had no idea families had been added to C2! I was still patiently waiting, expecting them to one day pop up in the same place they were in Classic, somewhere around C2's containers section in the left-hand panel :lol:


I suggest you to read the manual more often: https://www.scirra.com/manual/1/construct-2

not saying that with a mean spirit, just families are I think here since.. 2012? ( https://www.scirra.com/construct2/releases/r75 )


Yep, I've just not been active with C2 before :P Bought it at launch to support the Scirra team, but have been working with Construct Classic up until now.

Thanks for the link though, I'll definitely be paying more attention to C2 from now on!
B
15
S
8
G
7
Posts: 255
Reputation: 5,368


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests