How do I pass an instance through a function parameter?

Just started using Construct 2? Post your questions here

Post » Sat Jun 27, 2015 4:37 pm

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.
Last edited by lapinchatware on Mon Jun 29, 2015 2:44 pm, edited 2 times in total.
B
9
S
4
Posts: 14
Reputation: 753

Post » Sat Jun 27, 2015 4:52 pm

Pass the UID to the function and then use Pick by UID (on the Family object) to pick it and do as you need.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Jun 28, 2015 4:16 pm

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
Last edited by lapinchatware on Mon Jun 29, 2015 2:44 pm, edited 1 time in total.
B
9
S
4
Posts: 14
Reputation: 753

Post » Sun Jun 28, 2015 4:31 pm

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.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Mon Jun 29, 2015 2:56 am

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. :D

Thank you for your help!
B
9
S
4
Posts: 14
Reputation: 753

Post » Mon Jun 29, 2015 10:30 am

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.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Mon Jun 29, 2015 2:41 pm

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.
B
9
S
4
Posts: 14
Reputation: 753


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest