How do I pass an instance through a function parameter?

0 favourites
  • 7 posts
From the Asset Store
Assets for creating mountains and ravines environments
  • Hello everyone, I was a ghost guess user for some times and I'm now a new and shiny registered user with a name. Today is the day of my first topic on this friendly forum.

    As my subject title state, I'm trying to pass an instance to a function.

    I did make an example of what I'm doing:preStart2.capx

    I want to make a function I can reuse in different layouts. (that is the point of a function, right?) I want to pass an instance(three in my case) of an object to the function so I can do stuff with this specific instance. The instance will not always be from the same object but they can be from the same family. The instance will be create at the beginning of the layout so it is not generated dynamically. I know already which object will use the function.

    I've already read about IID and UID:

    Those references I found are not what I want or maybe I did not understood what IID, UID and function can do for me.

    Hope I give enough details for you users.

    Thanks you to take a look at this.

  • Pass the UID to the function and then use Pick by UID (on the Family object) to pick it and do as you need.

  • Thank you!

    I did thinked about this when I was reading documentations but I read in this post a comment of Ashley about the unreliable state of UID. It was in 2011. Maybe since then things changes.

    Anyway, I tried it and it's working well! Until I found a better solution, if there is one, i'll keep my function as it is.

    If someone wants to know how I did: preStart3.capx

    Thank you blackhornet

  • UIDs are only unreliable if you hardcode events based on the number you see in the GUI. That is a bad idea. But once the game is running, UIDs are the perfect way for picking objects.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I understand. I can pick the UID directly with instance.UID if I know there is only one instance of an object or selecting the first[0] instance with pick nth instance then save this instance UID in a variable. This way I don't hardcode UID and get the result I want without risking to load an unpredictable one.

    Good, I'm going back to work then.

    Thank you for your help!

  • That post is out of date now, since then we moved UID assignment to the editor so UIDs are predictable and can actually be viewed in the editor before running. That doesn't really affect the question though as far as I can see - either way, you can pass an instance to a function by passing its UID.

  • Yes exactly. My question is answered. It's good to know that I can trust and select UID from the editor. It easier.

    Again, thank you guys. I have a better understanding of those IDs.

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