Reference to object type

Get help using Construct 2

Post » Mon Nov 25, 2013 5:18 pm

Hello, im trying to make tower defense game.

Right now when my tower shoot - it shoot projectile that i manualy put into event. Problem is - if i want to have 50 or even more tower i need to create alot of same type events, so every tower type spawn its own projectile.

I want to make instance var in towers, wich will hold projectile type, and use this var in event. Is there any way to do that?
B
3
Posts: 5
Reputation: 185

Post » Mon Nov 25, 2013 6:32 pm

Families, bro.
Check out the manual page on them, it will explain better than me

but in short:

If you create the family 'tower', and give it some variables, all the objects you put into 'tower' will inherit that family's variables.

You can then refer to the family 'tower' in the events sheet like it was any other object.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Nov 25, 2013 8:04 pm

As soon as you give it an instance variable, can't you simply add a check to determine shot type ?


instance variable towertype="missle"

and compare instance variable   
towertype="missle", action shoot missles

towertype="bullet", action shoot bullets

that sort of thing
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Nov 26, 2013 4:30 pm

Still each of your tower has to be manualy binded to event, i was looking for solution to make one event-action for all towers in general.
B
3
Posts: 5
Reputation: 185

Post » Tue Nov 26, 2013 4:39 pm

It will always be necessary to tell the computer what you want to do with what object under which conditions. picking/referencing the object will be necessary.

You could use function with parameters if you only want one event.
One of the parameters could be the missile type.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 08, 2013 10:52 am

Ok, lets take another aproach.
I want to create a behavior that will spawn object, and type of object should be selected by string, rather then object picker.

I looked at sprit plugin, and found a spawn function that do 'Spawn another object' action. It leads to function in preview.js. It pass object type within a javascript object, so i need first to get this object type.

My guess is to find array that contain all object types and search required type by name (string) and then use default function to spawn new object.

Shouldnt be too hard, but i cant figure out where is object type array, so i could access them in plugin script. Also - object type name is uniqe per type? Becuase if not, i guess whole idea is dead.

May be some one know where is this array? Tnx for answers btw!
B
3
Posts: 5
Reputation: 185

Post » Sun Dec 08, 2013 1:45 pm

function is what you need here

TType= missle   --> call missle

TType= bullet   --> call bullet
B
19
S
6
G
3
Posts: 197
Reputation: 4,154

Post » Sun Dec 08, 2013 2:33 pm

I understand your solution. But if i have alot of towers its become problem. Also i have similar trigger to build tower, and there can be more mechanic wich will be hard to maintain and change.

Ok, i cant post URL to a pic >.< but ive got your idea - i need different solution.Flirer2013-12-08 14:34:00
B
3
Posts: 5
Reputation: 185

Post » Sun Dec 08, 2013 3:01 pm

I don't recommend using third party plugins that often, but maybe you should look into the nickname plugin, you can find it in the plugin section of the forum.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 08, 2013 3:17 pm

Sir, you saved my day!
Its looks like exacly what i need.
My thanks!

After i test it - absolutly awesome. Exacly what i need. Thanks again!Flirer2013-12-08 15:33:22
B
3
Posts: 5
Reputation: 185

Next

Return to How do I....?

Who is online

Users browsing this forum: blackhornet, MathNook and 49 guests