How do I select or create an object by instance name.

Get help using Construct 2

Post » Fri May 26, 2017 12:56 pm

I have a family (colors) that contains 3 objects (blue, green, red). I want to select or create each one of them by name. (dynamically)
I'm using a familie because they can be drag&drop and they behave the same way and the familie will contain much more objects.
I thought I had 2 options to achieve this, to select them by instance name or to create them one after one.

If I create one object from a familie it creates automatically all the objects from that familie. (not an option)
I didn't found a way to select the object by instance name ?!?! (weird because it's usually a very basic to do but doesn't seem to be an option)

How can I achieve this simple task?
Thx!
B
5
S
1
Posts: 5
Reputation: 335

Post » Fri May 26, 2017 8:32 pm

I'm not 100% I understand what you're getting at, but it sounds like the instance you're creating is spawned after dragging and dropping one of these colored objects, is that right?

I'm assuming you would need to toggle the type of object you're wishing to create (I'm conceptualizing a tower defense style thing here). If that's the case, maybe you can have a variable that changes to the name of whatever object needs to be spawned when you select it. Then, when the colored object is released, it spawns the object with the name of that variable and is destroyed.

Again, let me know if that's way off base.
B
55
S
32
G
23
Posts: 333
Reputation: 16,616

Post » Mon May 29, 2017 12:30 am

I just wanted to pick an existing instances.
In other language I could pick an instance from the instance name that's why I was confuse.

Solution:
I've sent the UID of all the objects from the family in a array and then I create an event "Pick instance with UID - UID number from the array" from the family.
It worked perfectly!

Thx for the reply! ;)
B
5
S
1
Posts: 5
Reputation: 335

Post » Mon May 29, 2017 11:40 am

I don't suggest using UID's to pick unique instances, because if you destroy objects the UID changes. You can add an instance variable to your family and every time you create object from it increment it by 1, then pick the instances with that ID.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,357

Post » Mon May 29, 2017 12:07 pm

cedlal wrote:Solution:
I've sent the UID of all the objects from the family in a array and then I create an event "Pick instance with UID - UID number from the array" from the family.
It worked perfectly!


Sure, that somehow works. And next ?

Are you going to write 4000 events to follow that up? Like ....

1/ If this .... then pick UID this ... and do this ...

2/ If that .... then pick UID that ... and do that ....

3 to 4000/ If something else .. then pick UID something ... and do something else ....

Should explain what exactly you wanna do.
At this point i am afraid that you gonna create a vehicle that will overshoot the moon.
B
33
S
18
G
27
Posts: 2,442
Reputation: 20,348

Post » Mon May 29, 2017 12:23 pm

@cedlal There is a plugin and a behaviour named "nickname". This enables you to give all your objects a nickname and then simply create any object by name.

So if you have a family and want to create a specific object in the family you simply just use the action "create nickname".

So it is a very very useful plugin that I highly recommend which saves you a lot of time and makes things a lot less complicated.

Here it is for C2:
plugin-nickname-behavior-nickname_t74522
B
52
S
22
G
12
Posts: 725
Reputation: 11,716

Post » Mon May 29, 2017 3:33 pm

@imhotep22 You are totally right! They explain how to do this in the documentation and it makes a lot of sense. :oops: I will pick the instance from the instance variable - ID instead of the UID provided by Construct.

@Anonnymitet It seems like a very useful plugin! Unfortunately I cannot use it, I'm already using C3 because I'm working on a mac and the plugin is not adapted to C3. I Hope it will in the future.

@99Instances2Go I'm picking a couple of objects randomly from the family and I add them to screen at random X position, the objects are created at runtime (no spawning).

Thx to all of you! :)
B
5
S
1
Posts: 5
Reputation: 335

Post » Mon May 29, 2017 7:22 pm

That is not how 'creating' works. If i understand you right, i still see no tree.

I have the impression that you try to pick/select an object and then try to create that object.

Picking an object in a parent condition has totally no effect on which object is created in the paired action.
Kinda logical, cant pick a non existing object.
B
33
S
18
G
27
Posts: 2,442
Reputation: 20,348


Return to How do I....?

Who is online

Users browsing this forum: blissfulwizard and 13 guests