How do I global variable as percent?

0 favourites
  • 5 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Example

    Player have global variable 'HP' default is 100

    Global variable - 'Armor' default is 5 (always absorb 5 damage)

    Global variable - 'Armor2' default is 50 (that means absorb 50% damage)

    Global variable "Damage" is 50

    so

    example 1

    When Enemy shoot at player and "Damage" is 50

    in Events should substract 25-5 (total substracted damage should be 20 'HP'

    example 2

    when 'Armor is 0 and 'Armor2' is 50 (percent)

    total substracted from 'HP' should be 25

    what i should type to calculate total enemy attack?

    now i have:

    when bullet collision with player>

    From 'HP' substract

    Damage -Armor - Armor2 ???

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So, you can do this like this:

    let damageAfterArmor, damageAfterArmor2;

    damageAfterArmor2 = damage * (100 - Armor2) / 100; // Damage mitigated by Armor2 (percentage)

    damageAfterArmor = damageAfterArmor2 - Armor; // Damage mitigate by Armor

    hp = hp - damageAfterArmor;

  • So, you can do this like this:

    let damageAfterArmor, damageAfterArmor2;

    damageAfterArmor2 = damage * (100 - Armor2) / 100; // Damage mitigated by Armor2 (percentage)

    damageAfterArmor = damageAfterArmor2 - Armor; // Damage mitigate by Armor

    hp = hp - damageAfterArmor;

    how this should looks like in events?

    did "damageAfterArmor2 = damage * (100 - Armor2) / 100" should be under Every tick condition or just when hit is caused?

    why your proposition is in two lines not in 1 line (event)?

  • i try figure out something simple, in one line but this dont work well on my example.

    When Damage is 100

    and

    armorPercent is 50

    caused damage is 75, why?

    can somebody can fix my code?

  • The 'value' should be something like this:

    (damage * ((100 - armorPercent)/100) - armor

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