How Do I Fix this Inventory Sort?

0 favourites
  • 10 posts
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • Hello, I have created a functioning inventory system for my RPG, and all of my items work except for my spells.

    Each item type (potions, spells, weapons, and game items) has their own category in the inventory.

    Obj_item_Potions_Inventory represents the items under the potion category in the inventory, each animation (ID_ManaPotion, Id_HealthPotion, ID_FireBottle) represent each type of of potion.

    Obj_item_Potions_Game, is set up the same way but represents items in the game world before they are picked up and placed in the inventory.

    All items are set up this way including spells (obj_item_spells_inventory & obj_item_spells_game)

    Currently Potions work exactly how I want them to, and so I mimicked the code for the spells, but it has not been working.

    Essentially the fireBottle potion under the potions category when middle mouse clicked in the inventory is equipped inside of the "Active Item" slot. While there, the player can click "Q" to throw fire bottles until he/she runs out.

    I would like the same to happen with spells only with the "Active spell" slot. I want the player to be able to middle mouse click a spell in their inventory, have the spell move into that slot, and while it is there be able to press a button on the keyboard to activate the spell until he/she runs out.

    My issue comes with switching out spells before use. Say I have an invisibility spell equipped and I'd like to switch it out for a monster spell without using the currently equipped spell. With my current code you are unable to do this, if you click on a different spell with one already equipped one of the spells is either destroyed or overlaps the equipped spell.

    I will post the code I have thus far, is there any way to fix this code so that when the player equips a new spell, the old one is simply returned to the inventory, and the inventory sort updates?

    Any help would be greatly appreciated!

    Example of the issues in game: youtu.be/dF2Y-eqA118

  • I'll give a general idea as it's a lot of code but you should store the active spell name or some kind of global var so you know you have something equipped, you may already have this then ok. When you select an active spell, if there already is one, you need logic to delete the old one unless adding the new one does this already, then having stored the name of the old active spell you can run the loot pick up function on it as though you are picking it up again so it will add to inventory - or clone the inventory item pick up function with aspects of it you want to keep and call it a spell swap function.

  • Yeah, there's a lot of code and without the project file it will be really difficult to help.

    I noticed that you assign a tag "Active spell" to the clicked spell. But do you clear the tag from the previously equipped spell?

  • drive.google.com/file/d/1b8fAfKoj6AEOg7IzsdJcq3lyyH0C32DA/view

    Here is the link to a copied version of the project file, the code in here is exactly What I have currently.

    dop2000 I did have logic to delete the tag but was having trouble getting it to work so I deleted it in an attempt to find a new way. In the project file I share here, "ActiveSpell" gets set, but there is no logic to clear the tag. I debated on eliminating that global variable entirely.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Could you explain how to add different items to the inventory, how to open it, steps to reproduce the issue?

  • Yes of course, You open the inventory with "I" on your keyboard. There you will see all of the available slots and active slots.

    Use the arrow keys to get within 300 pixels of an item sprite you wish to pick up, you'll know it can be picked up because its name will appear when you hover your mouse over it. To pick up an item, right click it while in range.

    Now the item should be in your inventory when you click "I." In order to use the item, middle mouse click on the item sprite in your inventory. For firebottles, this should move the item to your active item slots, for mana and health potions this should increase either your mana or your health. Once a firebottle is in your active slot, you can use "Q" to throw them in the direction of your mouse.

    I'd like for the spell scrolls to do the same as the firebottles only instead of active item slot, they go to the active spell slot. (I will code the actual functionality of the spells later).

    Firebottles were easy because that is the only potion animation that requires a position change, as you can see each category of item is separated by game sprites and inventory sprites (what you see in game vs what spawns in your inventory), with each item in that category being represented by its own animation.

    The trouble comes with spells in which every animation has to have the functionality of moving to the active slot, and replacing the current active scroll, moving that scroll back into the inventory.

    To find the exact code that handles all of this functionality, it is all under the "Main" event sheet, under the "Inventory System" group. There you will find a bunch of groups; most you can ignore.

    "Inventory Tooltips" houses the text that represents the amount of an item in a particular slot.

    "Inventory Action" and "Inventory Functions" are really the only ones I'm working with at the moment.

    "Inventory Action" houses the code to loot and drop items, as well as code to use items, which is still in progress for spells, but the rest of the items in that group are complete.

    "Inventory Functions" house all the functions of the inventory system that you may see sprinkled throughout the code.

    To reproduce the issue: Pick up all three spell scrolls from the starting area, and attempt to middle mouse click more than one, instead of the new spell replacing the old one, they simply overlap each other or destroy each other.

    dop2000 Please let me know if that was not clear, and I will try to be more concise and clearer.

  • sorry not arrow keys to move it is actually wasd.

  • Wow, you didn't make it easy.

    and replacing the current active scroll, moving that scroll back into the inventory.

    Where exactly is this code that should move the previous scroll back into the inventory? Perhaps it should work like this:

    1. Check if there's an item in the Active Slot. If true - re-add it to the inventory, then destroy the item in the Active Spell slot.

    2. Move the clicked item to the Active Spell slot.

    .

    But to be honest, I don't like that the item is essentially removed from the inventory when it goes to the active slot. What happens if you pick up another copy of the same scroll - should it go to the active spell slot, increasing its quantity, or to the main inventory? How do you swap items in the active slot when the inventory is full?

    It will be a lot easier if the item assigned to the active slot stayed in the inventory. Just use a global variable, say ActiveSpell="invisibility". On right-click find the invisibility spell in the inventory, reduce its quantity by 1. If none left, remove invisibility spell from the inventory, reset the ActiveSpell variable to "". This is how it's done in most rpg games.

  • Yeah, sorry this is my first game, very new to this. Unfortunately, this entire inventory system is based on a YouTube Tutorial. I've been trying what you outlined for a while now and I'm still very stuck. Mainly because I can't seem to find any way to differentiate between instances of the obj_itens_spells_inventory object.

    My plan was to do what you said and eliminate the logic that deletes the instances from the inventory, and instead have a global variable that keeps track of the last instance clicked so that it knows what is selected. Then have logic indicating that while the global variable houses a particular spells animation name, all scrolls picked up with that name will automatically be added to the quantity within the active box.

    Any scrolls that do not match the name will be added to the inventory.

    I would then want to add logic that when a player clicks on a new scroll already within the inventory, that scroll's animation name will become the active spell variable, and it will be moved to the active box.

    I would then need to add logic that would somehow move the spell already in the active box back to the inventory.

    However, I can't even get close to that step because there is no way I can find that allows me to pick an instance of an object based on clicking. Is there a way around this, or should I just scrap this inventory system and rework it?

  • I would then need to add logic that would somehow move the spell already in the active box back to the inventory.

    But you don't need to move it back, because the spell should not have been removed from the inventory in the first place!

    When you assign some scroll/potion to the active slot, the inventory should not change. The item stays where it is. Only the global variable changes, and an image of the scroll appears in the active slot - you can even use a different sprite to make it less confusing.

    .

    That youtube tutorial you found isn't very good.. Usually an inventory system is based on an array or JSON object. All collected items and their quantities are stored in the array. When "I" is pressed, the inventory screen is dynamically generated from the array data.

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