Get object by UID ?

For developers using the Construct 2 Javascript SDK

Post » Sat Aug 20, 2016 4:30 am

Hello, I know that the function "this.runtime.getObjectByUID(uid)" returns specific object.

I want to know if exists way to pick not the specific object by his UID, but like if I pick it with "AddObjectParam" (In the edittime.js). And then I will be able to pick this object by IID (I know how to do this, this is not the problem).

Why ? To pick object by his UID and his IID. So the UID permits me to pick the object "type" and the IID to pick instance of this object.

It's difficult to explain... but I think that you understand me! Thanks
Last edited by Saad Swad on Sat Aug 20, 2016 8:34 am, edited 1 time in total.
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Sat Aug 20, 2016 8:33 am

Or exists method to get all UID (in array?) of an object by one UID ?

Or why not "this.runtime.getObjectByName(name)" ?
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Sat Aug 20, 2016 9:01 pm

Not sure what you need exactly, but there's a "trick" to pick by "instance name". Basically you add an instance variable (let's call it "instanceName") to your object/family and then you pick by System -> pick by comparison. As a first param you type object.instanceName and in second parameter you type the name of instance (it might be a groupd of course as well). This way you can pick any particular instance of an object or group of instances.
ImageImageImage
B
28
S
17
G
82
Posts: 1,031
Reputation: 45,906

Post » Sun Aug 21, 2016 1:23 am

When you use an object as a parameter the runtime gives you an object type. From that you can get a list of picked instances or a list of all the instances of that type. Iid is just an index in the instance list. The sdk manual should have all the info needed to do that, and for examples on how to do it look at existing plugins to see how they do it.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Sun Aug 21, 2016 6:24 am

@BackendFreak Thanks for your reply. If I don't find solution in the runtime I use your method.

@R0J0hound Thanks also. I don't found plugin which does this thing...
You can see here the steps :
1. I add my action 'set text' :
Image

2. My code in the runtime:
Image

So logically, the text of all instances of the object type which has the instance with the UID 'uid' will change.

3. I create project with the object text with three diferents instances with the UIDs : 0, 1, 2.
Image

So logically again, text of all instances will be set to : "set text in all instances"
Image

4. I get this error:
Image

Thanks for you help. I don't request any code, just links or a way...
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Sun Aug 21, 2016 9:51 pm

in your code "obj" is a list of instances, not one instance. In which case obj.runtime is undefined, and thus the error.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Mon Aug 22, 2016 6:57 am

THANKS A LOT !!!!!!!!!!!!!!!!!!!!!! ;D
B
17
S
10
G
19
Posts: 140
Reputation: 11,457


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests