Suggestion: Object ID

New releases and general discussions.

Post » Thu Mar 18, 2010 8:32 pm

I think that in some instances we will need to use a direct reference to an instance created (sprite or other objects).

So far if you have 10 instances of an object and you want to issue a command to one instance, you have to assign a private variable to all of them, and use a "for each" and "compare" and then you can issue some commands to the specific object. But this is slow and if you need it a lot in your project can slow down the fps and is quite annoying to code so much each time.

So my suggestion is this: another command in the system: system.create_obj_with_ID that can be used like this: "IDvar=system.create_obj_with_ID" to pass the unique ID to one of your vars at the time of creation. Then you can use a "obj(varID).do_stuff" to make the needed object to do what you want.

Obj can mean a sprite or any other classes.
The ID can be similar to a .com hwnd (unique and pretty large).
Also the direct reference can be optional (to be used only if needed).
An ID can also be used with a hash table or an array...

Thank you.
B
3
G
2
Posts: 14
Reputation: 703

Post » Thu Mar 18, 2010 8:36 pm

Each object has Unique ID. You can retrieve it using the Get UID expression or .UID suffix (ex. Sprite.UID).
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Mar 18, 2010 8:42 pm

Great.
But when you can get this id? and how you can use the ID to tell the object to do stuff?
Also, is this implemented in the action list or works only with a python script?
B
3
G
2
Posts: 14
Reputation: 703

Post » Thu Mar 18, 2010 8:56 pm

[quote="Cristi":2v87xjui]So far if you have 10 instances of an object and you want to issue a command to one instance, you have to assign a private variable to all of them, and use a "for each" and "compare" and then you can issue some commands to the specific object. But this is slow and if you need it a lot in your project can slow down the fps and is quite annoying to code so much each time.[/quote:2v87xjui]

That's not accurate. You don't need to have a "for each" loop to do this. A simple "compare a private variable" condition will do. I replied to your previous help/tech post with a basic cap example.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Thu Mar 18, 2010 8:56 pm

To get the unique id or UID of the currently picked sprite , use "Sprite.UID" in the expression editor.

No python needed.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Mar 18, 2010 10:10 pm

Or, when in the dialog that wants you to enter expression, double-click the object to get a list of available expressions.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Fri Mar 19, 2010 12:27 am

Thank you.

Problem solved
B
3
G
2
Posts: 14
Reputation: 703


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests