manipulate differents instance of same sprite

Get help using Construct 2

Post » Tue Nov 19, 2013 6:40 pm

Hi,
I got this : http://www.scirra.com/forum/pin-one-sprite-to-another-of-the-same-type_topic46515_post291421.html#291421

This is working. But here's a particular case I don't get, and since it's happening very often, there must be something I don't get !

A screenshot of the case :



As you can see, I got 2 instances of "Insecte", first one is chasing the other.
So far, I can have Insecte(0) and Insecte(1), displaying correct UID.

But for some reason, once I've reach Insecte(1), I can't change values from Insecte(0).
I've tried another approched (the disabled code in the end) with an external value to pick up the Instance but it doesn't work ...

Can you help me ?

Thanks a lot
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Wed Nov 20, 2013 11:18 am

I'm trying to tell in another way:



Foreach Insect :
- If Insect.hungry = 1
- - Pick Up the Nearest Insect (who is not the same, and fit to its taste)


So far : it's good, I got Insect (the victim) and Insect(0) (the predator)


PROBLEM:
How do I update the predator ?
If I make some changes to Insect, that will use the victim.
If I pick up the predator by UID, it doesn't work, probably because i'm in the Loop "foreach Insect" ..

There's a basic thing I don't get, if someone can tell me any method to do what I'm trying to do, it will be greatly appreciated.



BONUS SUGGESTION : that would be awesome to get some aliases, like in mysql, like :
- Pick up Insect.hungry = 1 as Predator
- - Pick up nearest Insecte (not me, etc) as Victim

Predator.target_uid = Victim.uid


What do you think ?

Cheers

Charles


B
8
S
4
Posts: 131
Reputation: 1,205

Post » Wed Nov 20, 2013 11:39 am

You should use subevents.

After you pick the insect which is hungry, pick the insect to chase in a subevent. In another subevent (as long as it is a direct subevent if your for each) if you reference an insect it will be the one originally picked.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Nov 20, 2013 12:31 pm

Thanks. It's a good idea and I figured out that my problem was also related to a bad use of "pick nearest"

I have to make conditions, then a sub event with just "pick nearest" to make it work.

B
8
S
4
Posts: 131
Reputation: 1,205

Post » Wed Nov 20, 2013 12:45 pm

Actually the sub event will only pick from the list of that instance already picked. So if one is picked, it won't see the other.

You can use families if you aren't using the free version.

You pick one by referencing the family it's in, and the other directly. So you have two separate picking lists.Paradox2013-11-20 12:45:45
B
230
S
62
G
33
Posts: 902
Reputation: 40,319

Post » Wed Nov 20, 2013 3:16 pm

okay thanks. I've seen families are made to host different sprites that would share some common behavior but your technique seems good as well to separate the same sprites yes !
B
8
S
4
Posts: 131
Reputation: 1,205


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests