Subtract a value based on a another value?

0 favourites
  • 9 posts
From the Asset Store
Human/Character Base Pixel Art Sprites in various poses (nearly 100 files)
  • Hi,

    I'm currently developing a game, where in the enemy upon bullet impact suffers a particular amount of damage. I added a power up which would increase the bullet's damage via Instance Variables.

    Now, I want the bullets damage to be added upon the original damage.

    How do I do so?!

    I've tried:

    Subtract from:

    10 + (Bullet.DMG)

    {10 here is the original damage, and Bullet.DMG is whatever gets increased)

    Is this right?! 'Cuz it ain't working.

    Thanks.

  • Assuming that Bullet is the object you've picked in the collision event and DMG is the instance variable, then that should be correct yes, although the () around Bullet.DMG aren't necessary.

  • With any help request it helps posting a capx to answer accordingly to how you exactly did things so far.

    theubie answer might be sufficient though (it depends, once again, on how you implemented your project so far).

  • Umm,

    In my game I made it as a global variable, for both the bullet and the enemy, whatever name but for example "BulletDamage" and "EnemyHealth" and when the bullet hits the enemy:

    Bullet -> On collision with another object -> Enemy -> Subtract "BulletDamage" from "EnemyHealth".

    And when you pick up a powerup, just make another event:

    Player -> On collision with another object (powerup) -> Add 10 to "BulletDamage".

    This way worked for me, hope it helped!

  • Jonsterz:

    Thank you, the Global Variable worked!!

    Just one more thing, since I really don't want to make a new post for it:

    How do I randomize a Instance Variable?

    I have a "Cash drop" that I want to be random. So whenever the player picks it up, it'll be a random number anywhere from 0 - 10.

    I tried random(0, 10) but then the "text object" I use to display it goes blank.

    Global Variable again?!

    Please help.

    Thanks!!

  • Jonsterz:

    Thank you, the Global Variable worked!!

    Just one more thing, since I really don't want to make a new post for it:

    How do I randomize a Instance Variable?

    I have a "Cash drop" that I want to be random. So whenever the player picks it up, it'll be a random number anywhere from 0 - 10.

    I tried random(0, 10) but then the "text object" I use to display it goes blank.

    Global Variable again?!

    Please help.

    Thanks!!

    First, check that the text box is big enough to display the text, if it's not big enough, it will go blank.

    Yeah, the random value works. Although I'm not quite sure you need to set the 0 value, I think it automatically sets that. Just have the amount of total cash you have, as a global variable.

    Example:

    Global Variable -> Cash.

    Event: Player -> On collision with another object (the cash object)

    Action: System -> Add to Cash ( And insert here, random(10) or random(0,10).

    Hope this hepled, and glad my previous tip worked!

  • Jonsterz:

    You were right, the text object wasn't big enough to display it.

    But apparently it wasn't big enough because my figure is going into ".123456".

    Eg. Upon collecting CASH, it goes to a random no. like "4" but with ".468828" added to it, making it "4.468828".

    Why am I getting the decimal with the digits after. I don't want those.

    Is there a way to just round up the number? Rather than it to show up something like this "4.2486224"?

    Please help?!

    Thanks!!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do it like this : round(random(0,10))

  • Do it like this : round(random(0,10))

    What he said.

    Cheers!

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