Dinamically create objects

Get help using Construct 2

Post » Fri Nov 01, 2013 1:44 pm

I was just wondering if it is possible to create an object just using his name.

Let's say I have a turrent and I have two types of ammunition, ammo1 and ammo2.
If I press a button I can change the ammo type, I save that info in a Instance variable string, so every 3 seconds I shoot the object saved in the instance variable as a name.

Its that possible?
B
10
S
2
G
1
Posts: 48
Reputation: 1,265

Post » Fri Nov 01, 2013 2:19 pm

http://www.scirra.com/forum/plugin-nickname-behavior-nickname_topic57943.html Nickname behavior might help you
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Fri Nov 01, 2013 3:02 pm

In the layout pane:
- Place the ammo in the margin (not in the layout itself)
- Give the ammo a bullet behavior
- Set the speed

In the shoot event that you will create:
- if instance variable is ammo1
- spawn ammo1
- set angle of ammo1 (angle of the turret)

- else if instance variable is ammo2
- spawn ammo2
- set angle of ammo2 (angle of the turret)

You can spawn by using the "create an object" under system

I hope that helps
B
4
Posts: 14
Reputation: 230

Post » Sat Nov 02, 2013 12:00 pm

Awesome Rabenmutter, yes this seems its he stuff im looking for.

AlKanadi, thanks for your answer but it's not really what I'm looking for. For example if we had 100 types of ammo that solution isn't going to be easy to maintain, I would have to do 100 if then else loops.

Putting the name or thenickname on a instance variable will help alot.

thanks!
B
10
S
2
G
1
Posts: 48
Reputation: 1,265


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests