How do I do a basic inventory?

0 favourites
  • 5 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • Hello, i'm new on this, and I do not know how to do some things.

    What i want to do is an inventory that changes the weapons by pressing a key.

    At first you have the punch, then later you take the other weapons.

    By pressing the same key, if you are not overlapping a weapon, change the weapon.

    Punch->Gun and Gun->Punch

    If you have more than 2 it would be:

    Punch->Gun->Sword Sword->Punch

    Here are some images:

    puu.sh/ynuXN/658e52c932.png

    puu.sh/ynv7Q/20518813f1.png

    puu.sh/ynvaK/424a12631b.png

    How can I do this?

  • You should have a variable that sets the active weapon (currentWeapon) and another that stores how many weapons you have available at the moment (availableWeapons). Then you'd have an event that toggles between weapons.

    availableWeapons = 3
    currentWeapon = 0
    
    On key pressed  |  Set currentWeapon = currentWeapon + 1 % availableWeapons
    [/code:5zotzexg]
    
    Hope this helps. Cheers!
  • Arrays always seem like good solutions for inventory. Or could use an instance variable with tokenAt/tokeCount. But lets do an example with an array.

    Make an array, lets call it arrayInventory.

    At the start of the layout sounds like you will want to add Punch/Fist to the array as they will always have that. Then you will want to set the size of the array to 1 x 1 x 1, as you only have one item in the inventory now. Don't skip this step, it is important.

    Then when the character picks up an item you can push the item to the back of the array. (note: this will make the size 2 x 1 x 1).

    If they lose an item then DELETE the item from the array, which will decrease the size back to 1 x 1 x 1.

    Then you can have a variable to keep track of current selection. Lets call it InvSel for this example.

    On change inventory button press:

    Add 1 to InvSel

    If InvSel > arrayInventory.width - 1 Then InvSel set to 0 (remember Arrays are zero based index)

    Set current weapon to inventoryArray.At(InvSel)

    Can change the first two lines to Set InvSel to InvSel > arrayInventory.width - 1 ? 0 : InvSel + 1

    It may sound like a lot but just follow the steps and look up info/reference on arrays as you go and it will be easier than you think.

  • Thanks guys.

    Finally I did it with arrays, and it's working well.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • emm... i got stuck at Set current weapon to inventoryArray.At(InvSel)

    Can change the first two lines to Set InvSel to InvSel > arrayInventory.width - 1 ? 0 : InvSel + 1

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