Instance variable problem

Get help using Construct 2

Post » Wed Jan 11, 2012 9:14 am

Hi!
In game i am trying to add a value to an instance variable, but it doesnt working.

here is the link to capx:

instance variable test

any suggestion?



B
19
S
3
G
5
Posts: 98
Reputation: 4,647

Post » Wed Jan 11, 2012 9:48 am

Last edited by Yann on Sun Sep 14, 2014 10:12 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 11, 2012 12:30 pm

Thx Yann!
My problem is that i want many bombs at the same time, and increase their HP after every 3th destroyed bomb (bomb counter).
B
19
S
3
G
5
Posts: 98
Reputation: 4,647

Post » Wed Jan 11, 2012 12:44 pm

I have not looked at your capx but if i undersrtand what your saying then try this:

Global var BombCounter[0]
Global var BombHP[1] // only needs 1 hit
Global var BombTimer[1.0] // add a timer for the bomb so you can increase the timer as the difficulty increases

System.onStartOfLayout
     -> System.setVale(BombCounter[0]) // this will benefit you later when you want to restart the game.

system.Every[BombTimer]Seconds
     -> System.CreateObject([Bomb], random(WindowWidth), -10)) // create a bomb at a random x position, and a y of - 10 so we dont see it spawn

/* Im not sure how your destroying the bombs but i'll pretend there with bullets or something similar */

Mouse.onClick[Left]
     -> System.createObject([Bullet], Mouse.X, Mouse.Y)

Bullet.OnCollisionWithObject[Bomb]
     -> System.addTo(BombCounter[1])
     -> System.addTo(BombHP[1])
     -> Bullet.Destroy
     
System.CompareVariable(BombHP > 1)
     -> Bomb.Destroy

System.CompareVariable(BombCounter > 3)
     -> System.setValue(BombCounter[0]) // set it to 0 so we can count again
     -> System.SetValue(BombTimer[BombTimer - 0.2) // increase the speed the bombs spawn at

Note, This was rushed and straight out of my head, If you need a example capx let me know
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Wed Jan 11, 2012 1:17 pm

its getting complicated

if i declare a global variable for bombs HP then the bombs will share

the same HP if i think right and thats not what i need.


in my final game i will have many types of bombs (with different

properties), when the player goes from one lvl to another i need to

change these properties (instance variables).

question is if i change the instance variable of a given type bomb

then all of his instances will have that HP before hit?
B
19
S
3
G
5
Posts: 98
Reputation: 4,647

Post » Wed Jan 11, 2012 2:02 pm

I think what you should do here is keep a global variable BombHP that is the value you'll be modifying over time and that will get affected to the bomb instances on creation.

Based on your original capx
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Wed Jan 11, 2012 2:38 pm

so i have to set value for every spawned instance.

nice!

thx Kyatric!
B
19
S
3
G
5
Posts: 98
Reputation: 4,647


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], DiabloOvermind, emoticon and 16 guests