Function to set a variable to clicked objects instance var.

0 favourites
  • 10 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • At it's simplest level I want a function that will set a variable to one of the instance variables held within a clicked object.

    In my function I can tell which object in the family was clicked and change it's properties but seemingly can't access it's instance variables, such basic feature.

    I currently have a massive if block, i.e. if this object set this, but this is getting retardedly long and should be possible with just one event?

    Am I missing something, is this possible?

    Cheers

  • Can't you do "System" then "Global & Local Variables - Set Value" and have "[your family's name].[name of its instance variable]" in the value area (without the quotation marks, of course)?

    Did I understand what you were asking correctly?

  • Hi VonFirflirch , you've understood perfectly though sadly this doesn't work.

    I guess because at design time the editor doesn't know what inst. variables the selected object will have, though you would have thought it could look at common variables amongst family members

    Cheers.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you need common variables, then you add them to the Family, otherwise they are always unique to the object.

  • I dont know I understand you right.

    Something like this:

    Edit: I marked the problem zones.

    Edit:

    No answer?

    Ok so I post it simply, if it is this problem or not.

    That should be work:

  • Thanks for the reply but this isn't what I'm looking for, unless I've misunderstood your source (also nice theme ).

    Here is an excerpt from one of my functions:

    I would like to add two instance variables per object, name and displayName and then do something like this:

    If clicking on family item:
      set lastProp to [selected] familyitem.name  
      Append [selected] familyitem.displayName
    [/code:2u3oi0ys]
    
    This would then cover all objects, or something similar so that I don't have to repeat my code 1000 times
  • Can't you just have "sprbin", "sprladder" and all the others into one family, then give that family two variables (LastProp and AppendText) so that you only need to have this event once :

    Touch -----> Is touching Family -----> Set LastProp to Family.LastProp and Append Family.AppendText

    Sorry if I goofed again

  • But this would have the same variables amongst all the objects in the family whereas I need variables specific to the object clicked, i.e it's name :\</p>

  • Instance variable values are different for each instances.

    In the case of a family, all the object can share a "LastProp" instance variable, though have its value different.

    What VonFirflirch said is the exact solution you are looking for.

    What you actually need to possibly modify in your project is the creation moment so that each instance of a specific object type (contained in your family) does receive the exact informations ("names") you want.

    But otherwise, that's exactly what families and family instance variables are here for.

  • Ah yes! You are absolutely right, thanks so much guys. I'm sorry, I made some incorrect assumptions about family variables.

    This will save me no end of time

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