Instance variable problem

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • 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).

  • 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 <img src="smileys/smiley1.gif" border="0" align="middle" />

    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

  • its getting complicated <img src="smileys/smiley4.gif" border="0" align="middle" />

    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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • so i have to set value for every spawned instance.

    nice! <img src="smileys/smiley4.gif" border="0" align="middle" />

    thx Kyatric!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)