How create obj by name?

Get help using Construct 2

Post » Fri Mar 23, 2012 2:15 pm

How create obj by name?

thanks for support.

Create HTML5 games

Create HTML5 games
B
11
S
3
Posts: 12
Reputation: 1,535

Post » Fri Mar 23, 2012 2:58 pm

Add Event
Then add action
Action (system --> create object)

Then choose object to create
Set layer (through layer name)
Set X and Y

Hope this is what u are looking for.
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Fri Mar 23, 2012 3:15 pm

[QUOTE=Savvy001] Add Event
Then add action
Action (system --> create object)

Then choose object to create
Set layer (through layer name)
Set X and Y

Hope this is what u are looking for.
[/QUOTE]

thanks you. but.

I have a variable on the object(1), this variable can be named object(2).

I need to create the object(2) with that name.

how?vnHarry2012-03-23 15:16:56
Create HTML5 games

Create HTML5 games
B
11
S
3
Posts: 12
Reputation: 1,535

Post » Fri Mar 23, 2012 3:30 pm

For that i dont have the answer.

If i usualy need specific instances i just create more then one of the same object, and then pick the instance out of those that i need.
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Fri Mar 23, 2012 3:39 pm

[QUOTE=Savvy001] For that i dont have the answer.

If i usualy need specific instances i just create more then one of the same object, and then pick the instance out of those that i need.
[/QUOTE]

For example:

I have an object with variable slot1.


Event

right click
-if (obj.slot1 == 'bullet1') then
-- spwan bullet1 object on layer ....
-if (obj.slot1 == 'bullet2') then
-- spwan bullet2 object on layer ....

My problem is I have more than 50 bullet.

Create HTML5 games

Create HTML5 games
B
11
S
3
Posts: 12
Reputation: 1,535

Post » Fri Mar 23, 2012 3:49 pm

Do you really need 50 different objects ?
You could use a single sprite with 50 different animation frames, and on creation of the bullet make something like :
Bullet.Animationframe = obj.instanceVariable
Where instance variable is a number corresponding to the frame.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,786

Post » Fri Mar 23, 2012 3:54 pm

This isn't supported because as part of minifying and obfuscating your project on export, object names are removed to make it even more difficult to reverse engineer a project.

Allowing creating objects by a variable would then force C2 to include the original names of all objects, possibly making it easier to reverse engineer the project. TBH I think the best solution is a series of subevents like you've shown.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,208

Post » Fri Mar 23, 2012 3:57 pm

[QUOTE=Kyatric] Do you really need 50 different objects ?
You could use a single sprite with 50 different animation frames, and on creation of the bullet make something like :
Bullet.Animationframe = obj.instanceVariable
Where instance variable is a number corresponding to the frame.[/QUOTE]

thanks. a good idea.

I use obj because each object has a few initial values such as name, mindag, maxdag, firerate, speed, ... vnHarry2012-03-23 16:03:01
Create HTML5 games

Create HTML5 games
B
11
S
3
Posts: 12
Reputation: 1,535

Post » Fri Mar 23, 2012 4:05 pm

[QUOTE=Ashley]Allowing creating objects by a variable would then force C2 to include the original names of all objects, possibly making it easier to reverse engineer the project.[/QUOTE]

Uh, I understand, it's a trade-off.

I had try to create instance by name before (in plugin), but fail.rexrainbow2012-03-23 16:06:38
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Mar 23, 2012 4:45 pm

[QUOTE=vnHarry] I use obj because each object has a few initial values such as name, mindag, maxdag, firerate, speed, ... [/QUOTE]

Hold the initial values in an array and apply it on creation of the instance.
Once again, obj.instanceVariable can act as the index for an array.at(obj.instanceVariable)
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,786

Next

Return to How do I....?

Who is online

Users browsing this forum: BackendFreak and 21 guests