How do I count numbers and add needed numbers? (SOLVED)

0 favourites
  • 9 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • For example i have 3 variables:

    -ammo left "100"

    -ammo in clip "12"

    -max ammo in clip "12

    In Events:

    now when i fire pistol two times ammo in clip should show "10" because 2 was fired

    When i tap "R" key to reload

    events should check how many bullets are missing to fill -max ammo in clip

    so when i tap "R" from -ammo left variable should be substracted only 2

    or when i fire 5 bullets, in ammo clip should be 7 left and when i reload, to max ammo clip should be added 7 and events should substract 7 from -ammo left

  • When you reload subtract (max ammo - clip ammo) from ammo left, then set clip ammo to max ammo.

  • When you reload subtract (max ammo - clip ammo) from ammo left, then set clip ammo to max ammo.

    its working

    next and last step, when my Ammo Left lets say is 3 left

    when i reaload still clip ammo is filled to max (and ammo left is -9) but will be good to add only 3 when only 3 ammo is left ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Create a sub event and compare on reload : if (maxammo-clipammo) greater than ammoleft, add ammoleft to clipammo and set ammoleft to 0. ELSE do the previously mentioned logic.

  • Create a sub event and compare on reload : if (maxammo-clipammo) greater than ammoleft, add ammoleft to clipammo and set ammoleft to 0. ELSE do the previously mentioned logic.

    thank You !

  • Create a sub event and compare on reload : if (maxammo-clipammo) greater than ammoleft, add ammoleft to clipammo and set ammoleft to 0. ELSE do the previously mentioned logic.

    Hello again, im wondering, its possible to make this same events but without global variables?

    i try to make something similiar but with instance variables of One sprite.

    If sprite have instance variables:

    -'ammoleft' "100"

    -'ammoinclip'

    -'maxammo' in clip "12 (this variable can stay as a global variable if that help, because maxc ammo clip i can change easily in events)

    -'Type' 0 or 1

    type 0 means is inventory type sprite and should be storage for 'ammo left' instance variable.

    type 1 means its weapon, and use 'ammo in clip' and 'max ammo' too

    so i have in layout two sprites (the same sprite object) with variables:

    'Type 0' and 'ammo left' is 100

    and

    second sprite 'Type 1' its storage for 'ammo clip'

    When i tap 'R" reload weapon and fill clip size

    After shoot, from sprite 'Type 1' substract 1 from his 'ammo clip' variable

    (Because in future when i add other weapons, each weapon should not use this same global variables)

  • The easier thing to do is add more global variables if you have different weapons. pistolAmmo, shotgunAmmo etc. You can have another variable for 'currently equipped weapon' where 0 is pistol and 1 is shotgun. You subtract from ammo depending on the equipped weapon.

    When you use instance variables like that all you're doing is moving what could be a global variable into a more difficult way of doing the same thing because now you have to pick instances.

    You could think about using instances and variables if your items and ammo are being stored in an inventory array, then they could relate easier but I think you're not using an array.

  • The easier thing to do is add more global variables if you have different weapons. pistolAmmo, shotgunAmmo etc. You can have another variable for 'currently equipped weapon' where 0 is pistol and 1 is shotgun. You subtract from ammo depending on the equipped weapon.

    When you use instance variables like that all you're doing is moving what could be a global variable into a more difficult way of doing the same thing because now you have to pick instances.

    You could think about using instances and variables if your items and ammo are being stored in an inventory array, then they could relate easier but I think you're not using an array.

    I try use many global variables before, for each ammoType, this dont works well with inventory slots. Example: its impossible to make two this same ammo type in two other slots

    Slot1 12x ammo, Slot2 24x ammo

  • You'll have to share the project so I can see how you've made the inventory.

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