Picking an object that is in two specific families

For questions about using Classic.

Post » Fri Nov 27, 2009 9:43 pm

Hello,
I am not sure about this, maybe I am just tired, but I have a problem:
I have one family for each player (Red Player, Blue Player, etc.). Those families hold all structures and units in my game.
Now, I have separate families for those as well (Units for my units and Structures for my structures).

What I need to do is this:
Get the coordinates of my mouse cursor (I know, MouseX and MouseY) and see what friendly structure is closest to it.

For example:
I am the blue player, my cursor is closest to a red structure. However, this is not the one I want to pick in my game code. I want to ignore all structures but the blue ones and there pick the closest one.

The way I see it, my only means of doing so would be to split the player families further, so that in addition to Units, Structures and Blue Player I would get Blue Structures and Blue Units.
If at all possible, I would like to prevent that for sanity's sake. ;)
Any ideas? Maybe something I just overlooked?

Cheers,
Sebastian
B
3
G
3
Posts: 14
Reputation: 903

Post » Sat Nov 28, 2009 8:49 am

+ On Mouse click
+ Blue: Pick closest to MouseX,MouseY
> Punt the garden gnome

I'm not really sure what you describe, but if you want to pick the closest member of Blue family to the mouse coordinates, that is the way to go.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Nov 28, 2009 9:22 am

Thanks for your reply.
I don't want to pick the blue member closest to my mouse, I want to pick the blue member closest to my mouse that is a structure.
It would look like this:

For all Structures in Blue Player
Pick object closest to X/Y (MouseX, MouseY)

Just that I don't think Construct supports something like that without using arrays. However, using arrays for this just feels...dirty. I was looking for a more elegant way to handle it.
B
3
G
3
Posts: 14
Reputation: 903

Post » Sat Nov 28, 2009 9:30 am

I see, you just want to pick structures within Blue family... Hmm.

Well, personally I prefer private variables when it comes to situations like this, because this allows me to switch them around (like capturing a building, which would then from reds go to blues).

So, if you gave your structures a private variable, say 'Faction', you'd just do it like this:

+ Structure('Faction')="Blue"
+ Structure: Pick closest to MouseX,MouseY
> Drop a stink bomb onto neighbour's doormat

Basically it first selects the structures that belong to Blue player, only then it selects the one closest to mouse. Hope this helps.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Nov 28, 2009 10:11 am

This was exactly my question, thanks :)
I wasn't sure if once you picked a set of objects by saying
Select all structures where faction = "Blue"
the next picking of object (pick object closest to...) would take place in that already picked set of objects or in a fresh, unfiltered set of all objects in the family :)
B
3
G
3
Posts: 14
Reputation: 903


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests