How do I implement a function with families

0 favourites
  • 8 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I found a repetition in my code and would like to replace it with a function but haven't had any success yet. As you may have guessed it's a picking issue. I guess I still don't get it. Reading the families page hasn't helped me thus far and I'm hoping it's not a larger organizational issue. The newly created object is a different sprite for each "floor type" but they are all part of the same family - Rooms. Here's a snapshot of the problem area, I left the previous working code as a reference on 47

    At the end of a timer, a previously placed sprite is replaced by a different, new sprite, and I'd like the old sprite to pass it's instance variables over to the new one. I'd greatly appreciate your advice

  • Unless I misunderstood what you are after, there are not really anything you can do about it in this case. Whether you do it with a function or in the Timer trigger itself you will have to do it for each object, even though these might be part of the same family they ain't the same object meaning that Hotel and Casino are different objects, which you have to set individually. But you can do as you have done with calling a function to set the values as long as they are the same, if you don't want to look at so many actions. However to make your function work, you have change some things:

    First you need to pick the ConstructionFloor object as well as the Rooms object.

    And you have to change the way you pick to this:

    Room Pick instance with UID Function.Param(0)

    Since that is holding the UID that you pass to it in the call (Call "SetupRoom" (ConstructionFloor.UID <- This is Function.Param(0) since its the first parameter, the next parameter would be Function.Param(1) that's just the way it is, as C2 doesn't allow you to rename them.)

    So in the Function SetupRoom you add these two lines instead of the one you have:

    Room Pick instance with UID Function.Param(0)

    ConstructionFloor Pick instance with UID Function.Param(0)

    Then the function knows which elements you want to work with, and that should solve it for you.

    The way you call the function itself is fine, you don't need to change that.

  • Thank you for the detailed answer. I attempted your suggestion to no affect. I don't expect a solution but I am curious if I followed your direction correctly. I tried a few variations that yielded no results but they are basically the same. It's not a big deal to go with my original code, I just thought I could refine it a bit

  • Without the full code its hard to judge as I don't know exactly what your objects are, so its ofc a bit of a guessing

    However it seems that you don't need "Rooms Roomtype>= 3" as you don't use it for anything, unless something requires it to be more or equal to 3?

    There are some things you need to check:

    1. You have to make sure that you don't have several ConstructionFloors that are equal to 3, otherwise you cant be sure what you pass to the function.

    2. Is ConstructionFloor also part of Rooms family? if not then you cant use Param(0) to select it? In that case if Casino is part of the family, you can pass its UID as Param(1) and then select the Rooms using that instead.

  • To further complicate things, C2 doesn't let you pick a newly created object until the next top level event, so that's getting in your way too. One trick is to put a "Wait 0" before your function call. This will suspend the call until the end of the event sheet and call it then, allowing the pick.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To further complicate things, C2 doesn't let you pick a newly created object until the next top level event, so that's getting in your way too. One trick is to put a "Wait 0" before your function call. This will suspend the call until the end of the event sheet and call it then, allowing the pick.

    There shouldn't be any problems in this case, as its within the same scoop so passing the Casino object and picking the family object with it will work fine here.

  • Furthermore, he's picking his instances with "Pick by UID", which does not suffer from the infamous "newly created object" issue.

  • For anyone who may stumble upon this later and has a similar problem. I think a much simpler solution would be to use one sprite object for every room by distinguishing the different rooms via different animations within that same sprite object. For example rooms.sprite contains animations for Casino, Hotel, etc. This way you can detect room type via the animation and use a function easier since you are only working with one object. Haven't implemented it yet but hope that makes sense.

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