Clone enemies that take separate damage? oh boy :(

Get help using Construct 2

Post » Mon Mar 10, 2014 4:27 am

I feel like I'm making too many posts haha but the answers I'm after weren't in the manuals.

Simple concept. I want to make an enemy and then be able to ctrl+drag clone them all over my platform for really easy level building but the problem I'm running in to is they all have the same global variable and when one dies they all die.. Hero's best case scenario but programmers worst nightmare.

Any thoughts?

thank you.
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Mon Mar 10, 2014 4:37 am

TheSynan wrote:I feel like I'm making too many posts haha but the answers I'm after weren't in the manuals.

Simple concept. I want to make an enemy and then be able to ctrl+drag clone them all over my platform for really easy level building but the problem I'm running in to is they all have the same global variable and when one dies they all die.. Hero's best case scenario but programmers worst nightmare.

Any thoughts?

thank you.


https://www.scirra.com/manual/73/instance-variables

Instances variables are what you are looking for, Just create it for your ennemy, and use it instead of a global variable
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Mar 10, 2014 5:24 am

Message: TheSynan can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?

https://www.scirra.com/manual/73/instance-variables

Instances variables are what you are looking for, Just create it for your ennemy, and use it instead of a global variable



Thank you, I was just thinking this was the same sort of thing I will need to use on my "ammo".
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Mon Mar 10, 2014 8:41 am

Use instance variables for things each enemy "own".. ;)
I will not let you reach the sisters
Nature Forums
B
11
S
5
G
2
Posts: 496
Reputation: 2,306

Post » Tue Mar 11, 2014 5:25 am

Message: TheSynan can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
TheSynan wrote:

https://www.scirra.com/manual/73/instance-variables

Instances variables are what you are looking for, Just create it for your ennemy, and use it instead of a global variable



Thank you, I was just thinking this was the same sort of thing I will need to use on my "ammo".


Well, everything is working awesome now but I'm not able to reference the instance variables in text boxes. At least I don't know how anyway. I'm working on a project where I need to visually see the "Health" of the object/enemy. With a global variable I was able to easily reference the value with the "Set Text" action but for whatever reason the instance variables are not able to be called the easy way. How do I make the instance values show up in the text boxes :(?
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Tue Mar 11, 2014 7:47 am

I'd like to ask a further question.
If I want 5 enemies to randomly have health between 20 & 30, can I set an instance value of Health 20, and then set an event random command to give the individual enemies randomly different health?
B
27
S
9
G
2
Posts: 154
Reputation: 2,833

Post » Tue Mar 11, 2014 7:59 am

TheSynan wrote:Well, everything is working awesome now but I'm not able to reference the instance variables in text boxes. At least I don't know how anyway. I'm working on a project where I need to visually see the "Health" of the object/enemy. With a global variable I was able to easily reference the value with the "Set Text" action but for whatever reason the instance variables are not able to be called the easy way. How do I make the instance values show up in the text boxes :(?


You need to "pick" the objects which instance variable you want to display first. If you just do a set text how should it know which value to display if all your instances have different values ;)

There are a lot of post on picking in the "How do i FAQ" (sticky at the top of this forum)

You pick and instance and then use the instance variable.

If you want to display text or a hp bar for each individual object you can do something like this:
https://www.scirra.com/forum/viewtopic.php?f=147&t=97297&p=743346&hilit=individual+health+bar#p743346
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Tue Mar 11, 2014 8:00 am

@Doc AI
Can you help me? I have the same problem (already using instance variables)
comparing-x-coordinates-of-player-and-enemy_t98181

@TheSynan
Set text to

ObjectName.InstanceVariable

Sample:
Object name = Enemy
Instance variable = Life

Set text to
Enemy.Life

or you want a word before it

Set text to
"Enemy's life = " & Enemy.Life

I'm not sure which instance it will pick the instance variable from (if you have multiple instances of enemy object), but that should work.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Mar 11, 2014 8:01 am

Aurora Australis wrote:I'd like to ask a further question.
If I want 5 enemies to randomly have health between 20 & 30, can I set an instance value of Health 20, and then set an event random command to give the individual enemies randomly different health?


Yes you can. You set the default value when you create the instance variable, but the individual objects can have individual independent instance variable values (which you can change whenever you want for each individual object seperately).
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Tue Mar 11, 2014 8:03 am

@sgn15 have a look at the post i made just before you posted yours :)
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Next

Return to How do I....?

Who is online

Users browsing this forum: ChoosyZerk, Google [Bot], lukewasthefish and 17 guests