Identifying an object inside two families

0 favourites
  • 14 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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

  • 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.

  • 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...

  • 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..

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • Not really sure, but I think you want to have a for each ships in the shoot-event..

  • 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...

  • 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..

  • LittleStain Interesting... Without the for each, pickedcount shows the number of ships shooting (<1) and with the for each pcikedcount only shows 1, but still the one with the smallest UID is picked. Still having a very vague idea of why all of this happens!

  • So at least the for each is working as intended..

    The problem seems to be in the function, somehow the picking doesn't work as expected..

    Could you unfold everything inside the function?

  • LittleStain Here they are. I would upload the .capx, but really this is all there is to it!

  • I usually just use a variable to save my UID. Is there a reason why you are using a function to store it instead? Try running your game on debug, and look at the UID you stored. Is it correctly updating or is it staying at the same number?

    Just a tip, but when replying add a + their nick (eg rekjl), that way we will get a notification that you replied on the post.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)