How do I This System Inventory [SOLVED]

1 favourites
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • Hi, I'll try to be as soon as possible ...

    I'm looking for a system that works as follows ...

    When my character collides with the "Item" check an empty slot if empty set position to empty slot.

  • Hello o/

    There are probably many ways to do that, so I am going to tell you what I would do and then you see if it works for you, if it doesn't just come back here later and let us know because someone else might have a better idea.

    Well if the player will fill the slots from left to right, and then use the items at the same order, all you need is a variable to tell which slot is currently being used. If variable is 0 goes to the first slot and then adds 1 to the variable, and so on. And after you use the item just destroy it and subtract 1 from the variable.

    However, if the player can use the objects in any order he wants, then this means that the player can collect 3 objects, use the one at the second slot, and then you can't place the 4th item at the 3 slot again, nor at the forth.

    If that is the case you will need to select your slot object and on the object settings on the left you gotta set a Instance variable. This variable will tell if the slot is being used or not. Then when the player collides with a object you can set "system>pick object by comparison" and then you compare if the value of the variable of the slot (something like this slotName.instanceVariableName) is the same as the value that tells it is empty. The game will then select a slot that is empty and move the object there.

    Keep in mind, however, that this might result in objects being placed inside random slots and not in order from left to right.

    For it to be in order I would do something like, set another instance variable for the slots that works as their ID so they can be organized from 1 to 5.Then and set another instance variable, but for the objects this time, that tells if the object is at a slot or not.

    Then every time the player collects an object you go "system>for" set it from 1 to 5 and then compare if the object is at a slot and if the slot that has the same ID as the loop.index. This will check all the slots in order every time the player collides with something, and then once the object is in place the other checks will be false.

    I don't know if I'm being clear enough, but try and work with instance variable and loops, and if you need more details just ask o/

  • Hello! O/

    So... first, thank you very much for the help, I thought no one could answer me... I think I understood part of your theory ...

    Well, I created a new project and put everything in a very simple way...

    1 - I put ID's in the Slots using variables and I used the same duplicate sprite 5 times, putting different ID's for each one.

    2 - I also put a bollean variable to check if it will be Busy or Not.

    3 - Then I put an 8-way behavior on the character so he could move around the scene.

    4 - Then I put all the features that the character will pick up, also separating the items from the scene in layers. I hope you understand...

    NOTE: Open this image in a new tab, to see better, the site has cut.

    Now I need to know if it's more or less as you imagine it, or need to change something?

  • You are in the right path. Good job o/

    I think that a variable in the pick ups that tell if they are are on the floor or in the HUD can help you later on. But depending on how you use your layers that might not be necessary.

    Good work.

  • I have no idea what to do now ...

    The variable to know if the items are on the floor or the layer, must be boolean or numbers?

    How does "system> for" work in this case?

    And how do I get the functions if I collide with the items?

    I'm really lost

  • It's easy. First make a "Family" of all the "items" you have.

    Then, do this:

    For Each box:

    --- if box overlapping with Family ------ | Set box.occupied = true

    --- else ------------------------------------------- | Set box.occupied = false

  • Did you mean like that?

    The slot has not even changed to busy

  • You can use my template.

    https://www.scirra.com/store/royalty-fr ... coins-3380

    Regards

    Andy

  • Sorry, I'd love to buy it, but I'm trying to learn how it works :/

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • At this point, I'm trying to understand, what to do next...

    I've placed a text variable to indicate when items are on the floor, inventory, or mouse pointer.

  • willmonteirofx

    How about this solution? :

    https://www.dropbox.com/s/vl30jbms1ucpf ... .capx?dl=0

    Arrow keys to move the avatar, left click on an inventory item to remove it.

    I just use one item object with the different types set to separate animations, and one inventory object with the same animations plus "none". I then lay out multiple inventory instances.

    At the start I assign each inventory slot with a number (instance variable "no"), based upon its position; I'm using the distance expression to automate this, but you can assign manually if needed.

    Each time the avatar collides with an object the code searches for the inventory instance with the lowest "no" value and an animation of "none" and matches the animation to the object.

  • This is for sure, the most practical and simple inventory, good job! But I'm looking for a more complete and controllable inventory. Like that...

    1 - When colliding, set the item to the next empty slot.

    2 - Clicking on the slot item, it sets the tick position every tick to the Mouse.

    3 - When clicking on the floor with the item, the item spawn on the floor, in the same position as the mouse.

    And then the collision cycle returns...

    I'm having trouble organizing this little library of items and the question of positions too. There are many variables, I can not think correctly.

  • willmonteirofx

    Download the capx link again. Items were already being added to the first available slot, but I've also updated it as follows:

    Clicking on an inventory item selects it and adds it to your mouse.

    You can click again in the inventory to return an item to any slot. If there is already an item in that slot then it will swap the item.

    Click outside the inventory to add the object back to the floor.

    The text shows the currently selected item.

    Only one global variable and one instance variable! ;p

  • Huh! i'm tryng to to this, i'm back soon... '3'

  • Hello I'm back... good news! xD

    I implemented it and it is almost working fine ... due to the parallax of my "HUD" layer when I click on the item that is in the inventory, it is simply behind the slots, because it spawns in the "Principal" Layer. Ideally he should stay ahead. But if I make him spawn in "HUD" he'll just disappear before I even get him to drop.

    EVENTS

    Any idea how to solve it?

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