How do I reference an object in an instance variable?

Get help using Construct 2

Post » Tue Jul 08, 2014 4:25 pm

I have a family of sprites. I need to be able to create a particular one as indicated by the instance variable of another object. But I can't find any way to directly store an object reference in an instance variable. The best I've come up with so far is this:

Gonna_Get_Long.png

That works just fine, but I'm going to have over a hundred sprites in the family. Which means this sort of manual look-up table is going to get really unwieldy.

Does anyone have any thoughts about a better way to do this?

Thanks!
You do not have the required permissions to view the files attached to this post.
Last edited by TrickyWidget on Tue Jul 08, 2014 10:51 pm, edited 1 time in total.
B
8
S
2
Posts: 55
Reputation: 616

Post » Tue Jul 08, 2014 4:52 pm

B
51
S
16
G
9
Posts: 1,098
Reputation: 11,252

Post » Tue Jul 08, 2014 7:30 pm

spongehammer wrote:Maybe this could help..

Thanks for the tip! :)

That looks like it might be just what I need. I can create an instance from its nickname. However, so far I can't figure out how to get the UID of the instance that was created. Do you happen to know how to do that?
B
8
S
2
Posts: 55
Reputation: 616

Post » Tue Jul 08, 2014 10:10 pm

Try this, not sure if its what you want though.
You do not have the required permissions to view the files attached to this post.
B
51
S
16
G
9
Posts: 1,098
Reputation: 11,252

Post » Tue Jul 08, 2014 10:47 pm

spongehammer wrote:Try this, not sure if its what you want though.

Thank you for the effort. :)

Here's what I'm trying to do:

Nickname_UID.png

This creates a new instance of Sprite which was nicknamed "Monster", which is exactly what I wanted. However, now that I've created it, I need a reference to it so that I can work with it. So I need the UID or some other way of picking it.

Example attached.

Thanks again!
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 55
Reputation: 616

Post » Tue Jul 08, 2014 11:47 pm

Pick it by largest IID maybe?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Jul 09, 2014 12:18 am

codah wrote:Pick it by largest IID maybe?


Unfortunately, I don't have any way of knowing what object the instance was created from. So I wouldn't know what to search for an IID. At the time of creation, this "nickname" is all I have.
B
8
S
2
Posts: 55
Reputation: 616

Post » Wed Jul 09, 2014 7:27 am

Whats wrong with this then ?

You can store the UID of the sprite anywhere you like. Maybe i am just thick and not understanding the problem here. :) Which wouldnt be the first time :)
You do not have the required permissions to view the files attached to this post.
B
51
S
16
G
9
Posts: 1,098
Reputation: 11,252

Post » Wed Jul 09, 2014 11:24 am

spongehammer wrote:Whats wrong with this then ?

The trouble was that Sprite could actually be a great many different objects, so I couldn't reference them collectively that way. However, your proposal got me looking over things again, and I realized that I'd been a total idiot! The nickname plugin offers exactly the condition that I needed:

Nickname_UID_Solution.png

Voila! All I needed was to have all possible sprites in a family (which they already were) and then use the nickname picker (that I somehow overlooked like five times yesterday) to select it.

Thanks so much for your help! This will save me a great deal of effort. :)
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 55
Reputation: 616

Post » Wed Jul 09, 2014 11:49 am

Right i see what you needed now. Glad you figured it out :)
B
51
S
16
G
9
Posts: 1,098
Reputation: 11,252

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 37 guests