Pulling instance variables from *any* object

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.



  • You can do this with Families.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • as blackhronet said Families is your solution.

  • Ah ok.


  • 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?

  • 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 need to "Pick by UID" in the function. That gets the single object to process.

  • 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!

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


    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:


    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?

    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!)

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


    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.


    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.

  • 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.

  • Oook ok I feel really stupid now. I didn't realise that objects in a family inherited unique versions of the family variables. That was what I failed to understand (even though you consistently tried to tell me)! Thanks for your patience! I am going to bed now... X)

    I must have read that paragraph in the manual 10 times, and somehow still didn't get it.

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