[solved] spawning an object by name?

Get help using Construct 2

Post » Wed Feb 06, 2013 12:08 am


I did hunt for this.. does such a method exist?..

basically, i have turrets and want to store the string or some ref value that represents the type of bullet it will spawn..

I could then have something like Turret.Spawn(Turret.BulletType)

thanks :)matt752013-02-06 03:29:17
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Wed Feb 06, 2013 12:32 am

Unfortunately there no way to spawn objects by name at this time.

Easy solution to your problem would be use of instance variables for bullet sprite.

example in pseudo code:

bullet_type = 1 -> bullet.speed = 100
               -> bullet.power = 20

bullet_type = 2 -> bullet.speed = 200
               -> bullet.power = 50

then after spawning you need to set variable to proper value

+Turret spawn Bullet
+set bullet.bullet_type = 1
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Wed Feb 06, 2013 1:12 am

thanks :)
was hoping to avoid doing things like that.. but i guess it will just have to be.. seems strange that its not already there.. but then, i guess they have a big todo list..
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Wed Feb 06, 2013 1:23 am

haha!.. didnt even need to do this.. sorry. still trying to get my head around working with C2. managed to get obsessed with a single approach to the problem.. not that this wouldnt be handy feature.. thanks again :)
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Wed Feb 06, 2013 2:11 am

I haven't tried it myself, but maybe this plugin from rex_rainbow will do the trick: Nickname plugin
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Wed Feb 06, 2013 2:50 am

@Matt75 what solution did you end up using instead? Just asking as it helps to post the answer when you post questions, that way others with the same answer can find it. Also, if you do post the answer, could you update the title of the post with [Solved] in the subject.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Wed Feb 06, 2013 3:15 am

Try Nickname plugin as @boolean said.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Wed Feb 06, 2013 3:21 am

Thanks :) will check out that plugin :)

- Wasnt really a solution, just ended up i didnt really need to take that approach. Each of my turret sprites fires it own type of ammunition.. so all i really had to do was check if the turret is ready to fire and spawn the bullet sprite for that turret (i know, a little dumb). The problem stemmed from the fact i was using families, and thinking i should be firing bullets like this "Family.Fire()", which would spawn the correct bullet in a more abstract, and perhaps easier to maintain way.. but im happy to settle for none family approach in this situation..

"turret_flak.OnFire(FlakBullet)"

anyway, thanks for all your help :)
matt752013-02-06 03:30:10
B
6
G
2
Posts: 37
Reputation: 1,499


Return to How do I....?

Who is online

Users browsing this forum: Matthew de, semaso, Virpoja and 24 guests