Simulating a chest inventory

0 favourites
  • 5 posts
From the Asset Store
112 High-Quality Coins and Chest SFX specially crafted for video games
  • So I'm trying to find the best way to make a chest in my game. I originally tried to use an array but I don't know how to display the items in the chest doing that, nor do I know how to set each X value to a random number(loot generation). I instead made 10 variables on the chest which choose random numbers (each is an ID of an object/item). When you press E after having opened the chest, It adds ALL of them to your inventory. To make a selection of which item you want easier, I scratched that idea. I don't really want to go with the variable generation either, it seems tedious and a bad method. Let me explain what I'm trying to do.

    (Chest code for reference)

    So I came up with the idea to show a small chest inventory like the player inventory shows. So each inventory slot is an object and the frame determines the object ID and adds it to your inventory accordingly.

    What I wanna do is make it so all of these boxes for the inventory slots will do one of the following- Either move them to the chest you have opened and slightly to the left, or for each chest on the start of the layout spawn inventory boxes. But then it would be hard to set the UD and LR id's (that's how I get WASD control in the chest inventory)

    Also depending on how the above problem is fixed, I may need help creating random generation for the chests (If I end up going with random generation by chest instance variable, help with this part won't be needed). If each chest ends up spawning boxes at the start I won't need help, I have a concept that will work. If the boxes end up moving to the chest each time you open one I'm going to need a way to store the information of the chest contents and be able to retrieve them if you open the same chest, and adjust the inventory boxes accordingly.

    If you wish to mess around with it and test yourself, here is the capx. The troublesome code is on the "Object" event sheet and bookmarked. Press E to open the chest, TAB to close and resume control of the player- https://www.dropbox.com/s/6ujs1cjnoiia5 ... .capx?dl=0

    Any help is appreciated <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll probably need to use an array for this and I've created a very basic example here which does the following when you press 1 :

    • Generates random item list
    • Assigns the item to a slot linked with slot ID and the array position

    In short the way I make an inventory is to link the ID with the exact co-ord in the array, so slot with ID 1 has item 1,0 in the array, slot with ID 2 has item 2,0 in the array. You can then manipulate and move the data around however you want. Your generation of random items will probably be more complex than "choose" between items, that was just for this example, you could probably make use of number ranges that define item rarity and then item type.

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

  • Ok how would I get that generated on the start of a layout and saved to a sprite object, so that its not regenerating every time you open the chest?

  • You can assign the items from the array to instance variables on the chest, it's up to you how you want to do it. You could fill an array with random items and assign 1,0 to item1 and 2,0 to item 2 on the chest and generate the items again for each chest, or you could do it another way which is to have an array which contains every item in the game and set item1, item2 etc on the chest to a random item from the array. In the end it just depends how your game works and how the items in the chest are determined, but pretty much you are assigning a random item to a variable on the chest.

  • Okay thanks for the help!

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