Family member location

Get help using Construct 2

Post » Wed Feb 06, 2013 2:21 pm

Noob question...
I have a feeling that the answer to this one is simple, I'm just not able to grasp it at the moment...


I have a simple layout with sprites of family "Heroes" created on a tiled background covering the center of the window leaving the sides bare.

What I want:
When a hero - sprite is dragged and dropped outside of the tiled background the dragged sprites boolean "Selected" should turn to true.

When a hero - sprite is dragged and dropped inside of the tiled background the dragged sprites boolean "Selected" should turn to false.

What I have:
When a hero - sprite is dragged and dropped outside of the tiled background, all Heroes boolean "Selected" turns to true.

When a hero - sprite is dragged and dropped inside of the tiled background, all Heroes boolean "Selected" turns to false.

I cannot refer to a specific sprite object as all the sprites are generated randomly from the Sprites in "Heroes" family.

I assume that this might even be solved by placing the action inside the correct event. I tried with several possibilities, but alas, fail every time...


Please, what is wrong?

Link to my CAPX:
https://www.dropbox.com/s/fnecrxap6gxqpqa/CutthroatCaverns.capx

The fun happens on the Village layout. Ignore the rest...

This CAPX has a pretty nice Debug system that shows the UID of the sprites and the "Selected" boolean value when it changes.
So experimenting should be easy...


B
5
S
1
Posts: 18
Reputation: 436

Post » Wed Feb 06, 2013 2:36 pm

It does work, problem is in your debug text :)

Update texts in separate events like this:

Every tick
.. For each xtxtCharDebug
.. Pick nearest Hero
..... Set text to 'Selected: ' & Heroes.Selected

You were updating the texts without picking a hero, so they were updating the status of the first created hero by default :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Feb 06, 2013 5:16 pm

Ok, that probably works.
I tried originally to incorporate the action into the on mouse left button released, as it neatly knows which hero to assign the text Objects to. But it updated just once and then all heroes.

Could the effect be achieved some other way, maybe related to the mouse left button released?

Every tick, souds a bit overkill, as the purpose is just to see which heroes are selected in the start of the game.

After that the selection area will disappear and not be used any more...


Also I'm a bit worried of "pick nearest" as heroes can, theoretically at least, overlap each other...
<-edit-> I do assign the hero UID to every object related to the hero, so I'll probably manage to cook up something<-edit->


If you have another idea I'll be happy to hear it, if not, I'm happy already. Thanks!

B
5
S
1
Posts: 18
Reputation: 436

Post » Wed Feb 06, 2013 5:36 pm

[QUOTE=Tumba]

Every tick, souds a bit overkill, as the purpose is just to see which heroes are selected in the start of the game.

After that the selection area will disappear and not be used any more...


Also I'm a bit worried of "pick nearest" as heroes can, theoretically at least, overlap each other...
<-edit-> I do assign the hero UID to every object related to the hero, so I'll probably manage to cook up something<-edit->


If you have another idea I'll be happy to hear it, if not, I'm happy already. Thanks!

[/QUOTE]

You should not be too afraid of 'every tick', performance wise it is trivial.

Instead of pick nearest you can use 'pick by unique id' and use the UID in the object to pick the host hero, it is cleaner solution every way.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Feb 06, 2013 6:32 pm

Thank you for your help.
I'm still a bit shy of using every tick, as I will be wanting to show different thing at different times in the txtCharDeBug.

I solved it the other way around. When creating the hero and txt fields belonging, I assign a id variable to the hero for each object attached to it.

Thus, in this case, the hero will have the uid of the txtCharDeBug in its txtCharDeBugId variable.

This allows me to "pick by id" the fields I want when the hero is triggered, instead of monitoring each field each tick.

Oh, how I'd low to "pick [txtCharDeBug] pinned to Heroes" when f.ex. looping the Heroes... Would save tons of work, but alas....

Anyway, could not have solved it without your help.
Thank you very much!
Consider this case solved.

B
5
S
1
Posts: 18
Reputation: 436

Post » Wed Feb 06, 2013 7:49 pm

[QUOTE=Tumba]

Oh, how I'd low to "pick [txtCharDeBug] pinned to Heroes" when f.ex. looping the Heroes... Would save tons of work, but alas....

[/QUOTE]

I'd recommend you take a look at containers, they should simplify your loops. If you add hero and all pinned objects to same container then picking the hero picks all the container objects as well. Don't quote me on this though, might recall it all wrong.

Glad I could help :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests