Does Construct have a ID for each instance?

For questions about using Classic.

Post » Sun Feb 13, 2011 4:21 pm

I'm sry if i have a stupid question. I'm new and my english is poor...

Can i get the ID of instance when i create it and use this ID to set variable and action? I want to control each instance but i don't know how to do. When i try something with an instance, it do for all instances with same object. And when i want to select some instance with same object (same as RTS selecting unit) i have got a big problem. :< How can i do that? Please help me. :(

Thank for reading.
B
2
G
1
Posts: 15
Reputation: 480

Post » Sun Feb 13, 2011 4:49 pm

Yes each instance will have an id, the uid, but that wont help with picking.
The usual method for picking is to give the object a private variable, and when you create an instance give that instance a different value in its variable.
You can then compare that variable, and any instance with that value in its private variable will be picked.

>mouse&keyboard on left clicked
>-system create object sprite at 100 x, 100 y
>-sprite set variable to 1

>sprite compare private variable = to 1
>-sprite set x to 200
Image Image
B
161
S
48
G
90
Posts: 7,348
Reputation: 66,751

Post » Sun Feb 13, 2011 5:14 pm

Can't i use (instance_id).variable=x to set private variable of instance? *sob* That's too hard to make a game with so many instance if i must test all... Can you give me a demo? Thank so much for your help.

Bad... my mom is flamming, i must go to bed now. :(
B
2
G
1
Posts: 15
Reputation: 480

Post » Sun Feb 13, 2011 5:41 pm

If you give us an example of what you are trying to do we might be able to suggest something a little more specifically.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Feb 14, 2011 4:57 am

I don't know how to make a example with Construct and my english again is so bad. Can i use GML (Language of Game Maker)? It is a simple way i can to tell what i'm trying...

[code:38cyzzz5]
for(i=0;i<=350;i+=10)
{
//create the instance and get ID of it.
id_of_instance=instance_create(x,y,obj_bullet);
//use ID of instance to set variable.
(id_of_instance).direction=i; (id_of_instance).speed=5;
//or use ID of instance for event control.
//This make a same effect with the above.
//with (id_of_instance) motion_set(i,5);
}
[/code:38cyzzz5]

and this is product:

gmk file: http://www.box.net/shared/5f0xz7vmxk
exe file: http://www.box.net/shared/16ydbytiyp

I want to do same things with Construct, how can i? I'm going to make a bullet hell game. It have so many instance of bullet in a screen and complex movoments. Where is best way for it?

Thank so much for reading and help me.
B
2
G
1
Posts: 15
Reputation: 480

Post » Mon Feb 14, 2011 5:20 am

The UID of an object is based on all the existing objects, including text, behaviors etc.
So it wont help here, as it would be pretty hard to keep up with all of the possibilities.
However there's no reason you can't give each instance a value of your own choice.

[url:8r8b9v4z]http://dl.dropbox.com/u/666516/varpick.cap[/url:8r8b9v4z]
Note:
In this example I used a global variable as a placeholder for advancing the value of the variable.
Setting, or adding to a private variable is a bit tricky as each instance is given the default value on creation.
Image Image
B
161
S
48
G
90
Posts: 7,348
Reputation: 66,751

Post » Mon Feb 14, 2011 5:32 am

[quote="newt":phta09wl]The UID of an object is based on all the existing objects, including text, behaviors etc.
So it wont help here, as it would be pretty hard to keep up with all of the possibilities.
However there's no reason you can't give each instance a value of your own choice.

[url:phta09wl]http://dl.dropbox.com/u/666516/varpick.cap[/url:phta09wl]
Note:
In this example I used a global variable as a placeholder for advancing the value of the variable.
Setting, or adding to a private variable is a bit tricky as each instance is given the default value on creation.[/quote:phta09wl]
Thank you so much. Something i can't understand but it's really very great example for me! I can study more things than what i wanted! Thank you so much again! :D
B
2
G
1
Posts: 15
Reputation: 480


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests