Identifying an object inside two families

Get help using Construct 2

Post » Thu Nov 19, 2015 3:41 pm

I´ll go straight to the point.

Three families, each has its own instance variables (many of them, i´m actually worried it might affect performance). "shoot" (fireRate, etc), "players" (speed, etc) and "enemies" (steering IA). All players and enemies are inside of "shoot".

When the function "shoot" is called by a player or an enemy, said code will be executed using that instance´s "shoot" family variables. I´ve tried calling the function using that specific family´s UID as a parameter, and then picking the member of "shoot" with said UID, so it can read its instance variables. I´m pretty sure it doesn´t work as intended, because enemies trigger the function correctly but the code itself is unable to identify the correct instance of "shoot".

(I read all I can find about families, but still have some serious doubts about them. Any extra documentation would really help)

Thanks in advance
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Thu Nov 19, 2015 3:49 pm

If you need to, you can have the same objects in different families. I do that with my game, but you will need to be clear with your code as it might overlap sometimes, but it can prove very useful.

You can select an object inside a family just by its UID. You need to save it to a global, and as you mention pick it using the global. If you are having issues with selecting the UID, you can share a capx here and we will be able to help you out.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Thu Nov 19, 2015 4:04 pm

Wouldn´t it be the same as calling a function with the UID as a parameter? My biggest doubt right now is about family identification, I don´t know if the same UID would work for identifying an object in different families...
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Thu Nov 19, 2015 4:50 pm

CloveltOc wrote:Wouldn´t it be the same as calling a function with the UID as a parameter? My biggest doubt right now is about family identification, I don´t know if the same UID would work for identifying an object in different families...


UID = unique, so when referencing an object by uid there is absolutely no doubt which object you mean..
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 » Thu Nov 19, 2015 5:45 pm

Still, everytime I make a new family and implement stuff based on its variables, the results with more than one instance at a time are incorrect... I´ll read the families manual entry again, I guess
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Fri Nov 20, 2015 5:41 pm

Sorry for reopening, but I´m still attempting to fix this

The function seems to work fine, but I´ve noticed that if more than one member of a family shoots at the same time the correct number of projectiles are created, but in the incorrect instance. Per say, if UID 1 and UID 2 are shooting every "fireRate" seconds, 2 projectiles will be created on instance with UID 1, and none on UID 2. All projectiles spawn on the instance with the smallest UID, anyone knows why this happens? Still really misunderstanding families...

Edit: added some code snapshots
Image
Image
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Sat Nov 21, 2015 1:24 am

It's hard to tell from just that small part of the event sheet, but from the looks of it, when shooting, you are selecting an object by UID to fire. There will only be one UID selected so only one will fire. If you want multiple objects to fire, identify them by their conditions or else you will need to create multiple variables to select all their UIDs.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sat Nov 21, 2015 2:06 am

Not really sure, but I think you want to have a for each ships in the shoot-event..
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 » Sat Nov 21, 2015 10:58 am

@LittleStain Nope, same result... It should tell the right UID when executing the function for every ship with InputFire=1. I´ve got ships with different controls, but they´re all the same object (maybe that´s what causing this?), still, two of them shoot and projectiles spawn in the one with the smallest UID... Weird...
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Sat Nov 21, 2015 11:42 am

CloveltOc wrote:@LittleStain Nope, same result... It should tell the right UID when executing the function for every ship with InputFire=1. I´ve got ships with different controls, but they´re all the same object (maybe that´s what causing this?), still, two of them shoot and projectiles spawn in the one with the smallest UID... Weird...


I guess that the amount of ships picked in your "shoot" event is higher than 1..
You could check this by setting a text object to ships.pickedcount

My thought was the for each ship would solve this, but I might have overlooked something..
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

Next

Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 14 guests