How create obj by name?

Get help using Construct 2

Post » Fri Mar 23, 2012 5:14 pm

@Ashley
Is there no way to to do this using a variable or expression?
Its actually quite useful when creating a group of objects together.
Grouping for instances with different frames is problematic, plus that does nothing to help when you have to have different objects, tiled bg, sprite, particles... all together.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Mar 23, 2012 5:58 pm

@newt, if it was done the runtime would have to include a table of all object's correct names, which would help reverse engineers.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri Mar 23, 2012 6:06 pm

I have similar and made it
I have several Guns that need to spawn correct bullet type:

I did it like this:

Object Gun with animations (gun1,gun2,gun3,etc)
Then:
Object Bullet with several animations (bullet1,2,3,etc)

Global Text variable (type of variable depends on what you are doing)
Guntype=gun.animationname

Then

If guntype="animationx"
set bullet animation = guntype

i had to use a variable for other reasons, you could even set animation to gun.animation on every tick


Hope this helps

B
28
S
2
Posts: 69
Reputation: 1,491

Post » Fri Mar 23, 2012 6:06 pm

What about something like create by id, possibly assigning an id during runtime?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Mar 23, 2012 9:01 pm

Yes I need this feature too; I ended up with a long "switch" (as in the programming structure) that I keep adding to whenever I need a new object type created by the "factory".

Is it possible to create by "class ID" or something?
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Mon Mar 26, 2012 10:13 am

[QUOTE=Geo] Yes I need this feature too; I ended up with a long "switch" (as in the programming structure) that I keep adding to whenever I need a new object type created by the "factory".

Is it possible to create by "class ID" or something?[/QUOTE]

I think SC2 should do the same
Create HTML5 games

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

Post » Wed Jun 13, 2012 11:34 am

@Ashley

I would like to use a large layout with many instances in an Android project. To cut down the object count I am destroying the objects and referencing them in an array at the start of the layout and calling them when necessary.

The animation name method would be a reasonable way of creating objects by name. However I will be using a lot of different pseudo objects (i.e animations). This is difficult from a planning point of view in the layout editor.

In the editor you have an "initial frame" setting. Would it be possible to have an "initial animation" setting and also display the selected animation in the C2 editor?
B
29
S
8
G
4
Posts: 61
Reputation: 6,205

Post » Wed Jun 13, 2012 12:28 pm

I agree with the 'initial animation' setting. At the moment the only way t odo this is with han instance variable and an event.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Jun 13, 2012 1:11 pm

having a "create object with var name" would greatly benefit eventing, it would simplify events,+ be more dynamic, like been said, using animations or frames is not always an option or the preferred choice, i really hope something like this gets implemented
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Wed Jun 13, 2012 4:08 pm

I really cannot think of a place where 'create object by name' would be useful enough to warrant these security flaws. We have aniamtions and frames - shouldn't this be enough?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: jeffige, Mallets and 30 guests