Function to set a variable to clicked objects instance var.

Get help using Construct 2

Post » Mon Jun 15, 2015 9:13 pm

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
B
13
S
4
Posts: 65
Reputation: 875

Post » Mon Jun 15, 2015 10:20 pm

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?
B
12
S
3
Posts: 33
Reputation: 897

Post » Mon Jun 15, 2015 10:53 pm

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.
B
13
S
4
Posts: 65
Reputation: 875

Post » Mon Jun 15, 2015 11:05 pm

If you need common variables, then you add them to the Family, otherwise they are always unique to the object.
ImageImageImage
B
71
S
22
G
240
Posts: 3,732
Reputation: 133,990

Post » Mon Jun 15, 2015 11:23 pm

I dont know I understand you right.
Something like this:
Image

Edit: I marked the problem zones.

Edit:
No answer?
Ok so I post it simply, if it is this problem or not. :lol:

That should be work:
Image
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Tue Jun 16, 2015 6:55 am

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:
Image

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

Code: Select all
If clicking on family item:
  set lastProp to [selected] familyitem.name 
  Append [selected] familyitem.displayName


This would then cover all objects, or something similar so that I don't have to repeat my code 1000 times :D
B
13
S
4
Posts: 65
Reputation: 875

Post » Tue Jun 16, 2015 8:15 am

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 ;)
B
12
S
3
Posts: 33
Reputation: 897

Post » Tue Jun 16, 2015 9:12 am

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 :\
B
13
S
4
Posts: 65
Reputation: 875

Post » Tue Jun 16, 2015 10:54 am

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
291
S
114
G
95
Posts: 7,293
Reputation: 70,144

Post » Tue Jun 16, 2015 5:04 pm

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 8-)
B
13
S
4
Posts: 65
Reputation: 875


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests