Pulling instance variables from *any* object

Just started using Construct 2? Post your questions here

Post » Tue Oct 07, 2014 4:30 pm

Hi all. Is it possible to select a sprite's UID in an event without naming the object explicitly? For example, I want *any* sprite that walks into an area to send their instance variable to a function. At the moment, I have to pick the object explicitly via: System > pick nth instance > Object + UID. But I need to be able to say "no matter what the object, get instance variable Text1". Is there an option for this?

Reason being, I'm building a test-dialogue system, giving each sprite their own dialogue, and having it sent to the dialogue modal when the dialogue function is triggered. While it works well for simply talking to one instance and hardcoding them to send their dialogue over, I could streamline it greatly by having all sprites dialogue named similarly "Text1, Text2 etc" and simply having the function call the current object's Text1 or Text2. I don't know if this is possible, but I've had a hell of a time trying to find out. X)

I hope this makes sense. Help would be mucho grande. :)

Regards,

J
B
6
S
1
Posts: 28
Reputation: 465

Post » Tue Oct 07, 2014 5:58 pm

You can do this with Families.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Wed Oct 08, 2014 12:44 am

as blackhronet said Families is your solution.
B
12
S
6
Posts: 118
Reputation: 1,466

Post » Wed Oct 08, 2014 7:14 am

Ah ok. :)

Thanks!
B
6
S
1
Posts: 28
Reputation: 465

Post » Fri Oct 10, 2014 6:30 pm

Hey again, so I'm working with an object family now, and all these objects have their own instance variables containing their dialogue. ObjectA: Dialogue1, ObjectA: Dialogue 2, ObjectB: Dialogue1 etc. But I'm still having trouble trying to send these instance variables to my main function. I'm pretty sure it's just the syntax I'm using. I just can't figure it out.

I would assume I do something like:
Player On Collision with "Talkers" > Call Function "Pull Dialogue" (Talkers.UID)
Function On "PullDialogue" > Set DialogueHolder to Function.Param(0).Dialogue1

I thought this would find the current sprite by UID, and pass the instance variable 'Dialogue1' to the function - REGARDLESS of which object came into collision, it would find that object's 'Dialogue1' and pass it on ... but no matter what I try it says there's something wrong. Ideas?
B
6
S
1
Posts: 28
Reputation: 465

Post » Fri Oct 10, 2014 6:47 pm

You can create instance variables for the whole family too ;)

Click on family, and in properties on left side you will see Add/Edit Family Instance variables <---- that is where you can add instance variables that effect whole family.

So off top of head.... if family is overlapping area then send family.instancevariable

I don't use UID, I rather create a special UID I can understand.
instance var UniqueID=boxredinstance30 or something like that.
I usually load an array on start of layout that builds everything for me... so array has all x,y and instance variables etc.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Fri Oct 10, 2014 6:54 pm

You need to "Pick by UID" in the function. That gets the single object to process.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Sat Oct 11, 2014 5:19 pm

Hey Blackhornet. Yeah but that's the thing ... X) I can pick the collision object by UID fine, but it still doesn't work. I think I've been explaining this wrong, so let me use the magic of my super mad illustration skillz! :D

Here's what I'm after, and what I currently have:

problem-example-01.png


Now this is the thing: Each object's 'Dialogue1, Dialogue2' etc contain different strings. (Otherwise this would be pointless X) . I named the variables the same in each object so that the function could access the picked object's Dialogue1 no matter if it were Object1, Object2 etc. That's the actual goal here.

And the code:

current-code.png


So as you can see, when I try to pick the object's variable 'Dialogue1' it complains that it's erroneous. I saw an 'out of scope' message at one point ... this means it's picking the object, but can't see that the object has variables, right?

@Dotoit hehe yeah I know. But the aim of this is to get a variable from an object within a family without having to hardcode 'tell object1 to send it's variable to xxx'. The challenge is to pick Dialogue1 from no matter which object I collide with. :) Thanks though.

If you've already understood and posted the answer, and I somehow just didn't get it, let me know. But I tried what you suggested and still nada. Thanks again! :) (And sorry for bringing you back here again!)
You do not have the required permissions to view the files attached to this post.
B
6
S
1
Posts: 28
Reputation: 465

Post » Sat Oct 11, 2014 6:49 pm

There are two fool proof ways to do this...

1)
is you put them all into a family. You assign the family variables - variable 1, variable 2 etc
Then you fill in those variables on each family member.

2)
You have one object called which has multiple frames, frame1 is monster 1, frame2 is face, frame 3 etc
Now you drag that one object out 4 times and set the image frame for each...
Actually attached is a capx, quicker than explaining.
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Sun Oct 12, 2014 1:06 pm

Ah! That's clever (the frames solution), I never would have thought of that. Thanks a bunch! :) I'll rejig things and let you know how it goes.
B
6
S
1
Posts: 28
Reputation: 465

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: Studio Mercato and 0 guests