Asset - Scripts exINV - Inventory System

H

Homunculus

Guest

exINV is a general purpose, grid based (minecraft style), inventory system that will help you keep your item management clean and efficient.

The system provides a set of scripts to create an item database, manage multiple inventories, and provides user interface implementation on top of that, handling the logic and user interaction, including a crafting system and equipment selection.

Features

  • Database system built from CSV files (easy to edit using excel or a text editor)
  • Multi inventory management
  • Manages item stacking and individual item attributes (tags)
  • Ability to sort, search and count items in inventories
  • Read and write inventories from and to JSON format (for saving and loading mechanisms)
  • The UI and inventory data are totally decoupled, you can design your own UI from scratch
  • Shows how to create toolbars, equipment slots, and a simple crafting system
  • Extensive documentation and fully commented code

Marketplace link: exINV - Markeplace
Docs: Documentation and install guide
Demo (HTML5): Open demo
Price: 2.99$

Changelog


Version 1.6.1 - 3 Apr 2019
  • Bug fix: ex_inv_item_test_ext caused crafting to behave improperly. Please update and replace this script in your existing projects

Version 1.6.0 - 27 Gen 2019
  • Added an event system that allows instances to "listen" to changes in a specific inventory (ex_ev functions)
  • Added ex_db_add allowing creation of a database without relying on the CSV loader
  • Added database groups, allowing organizing and retrieving item keys by group
  • Migrated the draw events to draw GUI, adapting automatically to any resolution or view setting
  • Updated UI objects and scripts to take advantage of the new event system, resulting in cleaner and more readable code
  • Changed tags management so that the items tags ds_map is never exposed directly, making it less error prone. Important! Due to this change, ex_item_get_tags returns a copy of the tags ds_map, so you should remember to destroy it when finished!
  • Refactored ex_item_find to ex_inv_find
  • Removed ex_inv_updated, replaced by the event system
  • Refactored ex_tags_replace to ex_items_set_tags
  • Removed ex_tag_exists and ex_tags_size. They are redundant functions that simply call ds_map_exists and ds_map_size
  • All ex_ui scripts have been changes in order to accomodate the event system, please refer to the docs

Version 1.5 - 24 Apr 18

GMS2 only update. As of exINV version 1.5, the GMS1 version of this asset is to be considered legacy, and will not be updated except for bug fixing (see release post for details). I'll make sure to keep version 1.4 available for GMS1 as well as its documentation and support.
  • Cleaner, optimized and streamlined code
  • Improved namespacing and better organized asset folders
  • Refactored / renamed a few scripts with a better descriptive name (most notably, ex_inv_item_* scripts have been shortened to ex_item_*)
  • Revised UI and demo project that includes now examples for item drops, inventory toggling on key press, and simpler integration process
  • Added ex_inv_size and ex_inv_max_size to test the amount of slots in an inventory
  • Greatly improved ex_inv_sort, giving priority to non empty slots and allowing sorting by database attributes
  • Added ex_item_clear to make clearing a slot more intuitive
  • Added ex_tags_replace, to allow mass assignment of tags from a ds_map
  • Removed ex_inv_item_set_unique, due to tags making this functionality obsolete and being the primary cause for unexpected behavior
  • Adapted and extended the documentation

Version 1.4.1 - 23 Oct 17
  • Fixed a problem with a script variable referencing a instance variable instead of a local one
  • Added the possibility to pass a ds_map of tags directly to ex_inv_item_add and ex_inv_item_test

Version 1.4.0 - 28 Sep 17
  • Refactored most of the scripts with a better name and namespace. Scripts are now divided into 4 main groups: database, inventory, items, and tags.
  • Introduced item tags, allowing items to keep individual attributes without altering the base attributes, that are no longer writable
  • Improved user interface assets, making integration into existing project easier
  • Added ex_inv_resize to change the number of slots in real time.
  • Added ex_inv_item_copy, ex_inv_item_move, and ex_inv_item_test_ext
  • Scripts adding, removing or changing inventory items now accept a slot as an optional argument. Slot specific functions have therefore been removed.
  • ex_inv_write output has been changed in order to accomodate tags, and outputs a better formatted JSON representation of the inventory
  • Improved documentation with a step by step guide on integrating exINV into existing projects

version 1.3.0 - 21 Mar 17
  • New: ex_inv_test() , ex_inv_test_slot() simulate the insertion of an item in an inventory or slot
  • New: added basic view support
  • New: highlight toolbar items with digit keys example
  • New: hide / show panels example
  • New: chest implementation example
  • Updated documentation

Version 1.2.1 - 04 Oct 16
  • Add: ex_inv_item_set_unique, allows items to have unique attributes. Please note that due to this change previous inventories saved using ex_inv_write will no longer work with this version ex_inv_read.

Version 1.1.3 - 26 Sep 16
  • Add: ex_inv_read and ex_inv_write, allowing for easy inventory save / load

Version 1.1.2 - 24 Sep 16
  • Add: ex_db_keys - returns a ds_list of all the keys in the items database
  • Add: all functions requiring an item key as argument, now accept an item reference directly
  • Add: ex_inv_get_item, returns an item ds_map reference
  • Minor fixes and code cleanup
  • Updated documentation

Version 1.0.3 - 21 Sep 16
  • Add: ex_db_keys to get a list of all items keys
  • Fix: panel events are now better defined and called only when needed
  • Fix: reorganized messy code into scripts and renamed some ui scripts accordingly
  • Fix: minor text fixes (!)
  • Fix: added a workaround for GM:S bug 15583 that caused the crafting and equipment in the current stable version not to behave correctly
 
Last edited by a moderator:
H

Homunculus

Guest
Added version 1.0.1 with a few changes to comments on the code a cleanup of longer scripts
 
Last edited by a moderator:
D

Director_X

Guest
Hi. One quick thing I have noted on your documentation webpage is that the [Example] button only is working correctly with ex_db_load(file1,file2,...), whilst the other [Example] buttons do not show the black bg/white text colour correctly. Probably missing some HTML tag in there somewhere.

(Am using Firefox with permitted scripts.)
 
D

Director_X

Guest
Nope. Nothing is working now. :p (Unless it takes time for the server to update). When I click any [Example] - it just jumps back to top of the page!

Edit: Working now: Needed jquery scripts enabled! :)
 
Last edited by a moderator:
H

Homunculus

Guest
Hotfix: added a workaround for GM:S bug 15583 that caused the crafting and equipment in the current stable version not to behave correctly

For those using exINV on the GM:S stable channel at version 1.4.1757 , please update the asset, as that specific version introduces a bug that causes some features not to work properly.
 
H

Homunculus

Guest
I just released version 1.1.2

See open post for other notable changes in this version.

I also realize that the biggest shortcoming in this system is the lack of a way to save the inventory data. I'm working on this and I'll release soon an update that takes this very important aspect into consideration. Thanks for the patience.
 
Last edited by a moderator:
H

Homunculus

Guest
Released version 1.1.3, adding functions ex_inv_read and ex_inv_write, with ability to load / save inventories from and to string, allowing for easy inventory saving systems.

I'm currently working on a method to make items unique. This will allow specific items to get unique properties with respect to its database attributes, and prevent stacking with other items.

I apologize for the frequent updates in a short timespan, but I'm trying to cover as much feedback as possible about important features, in order to get this asset into a stable and fully usable state.
 
H

Homunculus

Guest
New version uploaded to the marketplace! This version adds the possibility to flag items as unique. Unique items will no longer stack with non-unique items of the same type or other unique items having different keys, but more importantly, they can have customized attributes with respect to their base items. Those attributes can also be changed on the fly. See the documentation for more info on this feature.

Please note that due to this change previous inventories saved using ex_inv_write will no longer work with this version of ex_inv_read.

With this update all the base features I planned to implement on this asset are done. This doesn't mean that development on exINV is finished, but future updates will depend on the feedback I receive and related requests.
 
H

hlr

Guest
Awesome asset by the way! I'm trying to figure out what the best way of just using the inventory for now. At game launch I want it hidden, and when I want to show the inventory I would press a button like "I". I see the code in room start, and I just commented everything but the inventory. How would I do this the right way?
 
H

Homunculus

Guest
@hlr It's quite easy actually if you start from the provided example. All you have to do is destroy the panel instance for the inventory. This does NOT delete the inventory, only its representation (and it's efficient since it's not just hidden).

When you want to display it again, you just create a new panel. This is already in the example and used when loading inventories from file, the old one is deleted and a new panel created.
 
Last edited by a moderator:
H

Homunculus

Guest
Version 1.3 is available on the marketplace!

This version includes a Game Maker Studio 2 version, a couple of new functions to test the outcome of inserting items in the inventory without actually adding them, a few updates to the example project, and a new documentation. See the open post for more info.
 
Last edited by a moderator:
F

foxtails

Guest
Thanks for the new update Catan :) Looks great!

Will you add an extra example using tab buttons to optionally switch between additional inventories using the new show/hide in the asset project?
 
H

Homunculus

Guest
Thanks for the new update Catan :) Looks great!

Will you add an extra example using tab buttons to optionally switch between additional inventories using the new show/hide in the asset project?
What do you mean by tab buttons exactly? The process to show / hide inventory panels is always the same, if you need a specific logic like having only one inventory panel open at a time, it should be quite easy to do. You just need to call inv_panel_hide(obj_inv_panel) to close all active panels, and inv_panel_show(...) on the specific inventory, every time a tab is pressed.
I don't think this needs an example, if that's what you mean, because that's exactly what the demo does with respect to the chest and the equipment inventory (one closes the other).

Right now I'm focusing on a few changes related to unique items, since in some specific cases the current system can be a bit of a burden to manage.
 
F

foxtails

Guest
Here is an example of tab buttons on inventory panel to switch and unlock new inventories mentioned in my previous comment. Button 1 and 2 on the right are different inventory panels and the locks are expanded unlockable inventories. Also, how do we define one inventory panel for just crafting items.
 
H

Homunculus

Guest
I think that as of now, tabbed panels like those should be separate inventories, switched on and off on demand. It should not be too difficult to add some logic that places items inside the next available inventory if one of those is full. Could be a nice feature to add to a new release though!

About crafting, there's the perfect example in the provided demo. It's just a regular inventory, but with some added logic to the panel. You should start with the one provided in the package and build on top of it
 
Last edited by a moderator:
H

Homunculus

Guest
exINV has been updated to version 1.4 ! Please refer to the main post for a major list of changes.

First of all, a warning on upgrading:
While in terms of major functionalities and structure not much changed from the previous version, almost everything has been refactored and touched in some way. Moreover, the introduction of tags changed the output of the ex_inv_write functionality and inventory format, as well as how individual attributes are assigned to inventory items (you can no longer change the base attributes directly). For these reasons, I strongly suggest not to upgrade to 1.4 in ongoing projects, unless you are ready to refactor quite a lot of code. Version 1.3 is still stable and has no known issues so far.

Version 1.4 is all about improving what was already there, starting from the received feedback. There are 3 major areas where the system has been improved:
  • Integration - The process to integrate exINV into your projects has been simplified and described in detail in the documentation. This was one of the major issues reported so far, I hope this update fixes it
  • Script names - Scripts are now grouped into a more meaningful structure, and their name has been changed accordingly to a better self explanatory version
  • Individual attributes - In version 1.3, in order for items to hold individual attributes, those had to be marked as unique. Moreover, the items base attributes could be changed. This approach is not only confusing, but also inconvenient to use.
    In 1.4, base attributes can no longer be changed, you can instead apply tags to you items (tags are essentialy a ds_map holding key - value pairs). Tags help keeping individual attributes separated from base attributes, and are easier to manage.
For any kind of problem or feedback do not hesitate to drop me an email.
 
H

Homunculus

Guest
Version 1.4.1 is available in the marketplace. This version fixes a problem with a variable being referenced as an instance variable instead of a local one, and allows tags to be assigned to items directly at creation, in ex_inv_item_add and ex_inv_item_test.

These changes do not break backwards compatibility, you can safely replace all ex_* scripts in your existing projects (assuming you are using version 1.4.0)
 
Last edited by a moderator:
H

Homunculus

Guest
Quick update: there's a problem with the function ex_inv_item_set, where the last argument is supposed to be optional, but causes an error if omitted. EXinv for game maker studio 2 has already been updated in the marketplace. The fix for studio 1 will be uploaded shortly. When upgrading you just need to replace the ex_inv_item_set script.
 

Morsayou

Member
Hello, for start thank you for this perfect inventory system. I just wanted to know if it exist an easy way to check if we have a weapon equiped in the inv_equipement.
Something like

If keyboard press Space {
use the weapon equiped in the left hand slot ;
}

Sry for my bad english, hope you understand.

Thanks.
 
H

Homunculus

Guest
It should be fairly easy. First of all, you'll need a setup where you know exactly which slot out of the ones in inv_equipment represents the left hand. Let's say it's slot 2 (you should consider labeling the slots using an enum, but let's keep it simple for this example).
Assuming the above, you can do it in different ways. The simplest one is getting the key or the item data from the slot and checking if it's empty (-1 if you get the item, empty string for the key). Something like this:
Code:
var item = ex_inv_item_data(global.inv_equipment,2);
if(item != -1) {
    //you have something equipped
}
As a sidenote, I'm going to release version 1.5 really soon. If you are just playing around with the system and it's not yet merged with your project, you may want to wait a little before doing so. It's worth the wait :)
 
Last edited by a moderator:
H

Homunculus

Guest
Not long, the code is done, I'm working on the docs, expect it during this week. Also, it's a GMS2 only release, if you are on GMS1 keep using the current version as that will not be updated (I'll explain more on this topic after the release)
 
H

Homunculus

Guest
Version 1.5 is ready to be downloaded, check the open post for a list of changes. Like the last update, due to some refactoring I advise against updating the asset in projects already integrated with previous versions, unless you are prepared to refactor some code.

Please note that this is a GameMaker Studio 2 only update

With the release of version 1.5, due to the sunset of GameMaker Studio 1 getting close, I decided to focus my efforts mainly on updating the GameMaker Studio 2 version. This was a tough decision for me, but I can no longer afford to maintain and update what in time become two similar but independent codebases. Especially with this update, I refactored most of the code behind the curtains to take better advantage of new GML features like ternary operators and layer based instance creation, making the gap between the two versions even bigger.
Version 1.4 is still a stable and mature asset, and I will definitely keep it available, as well as its documentation and support, as long as it is reasonably possible.

Cheers!
 

Morsayou

Member
Hello thanks for the update, its possible to have a list of all modified file ? Because i have work alot on the previous version and i dont want to rebuild evrything. And can i suggest u something like move inventory panel while clicked and a cross to close panel.
Because ur system look optimized for 2d platformer and a lot of people use topdown, and more example like toolbar item use, equipement item use.
Thanks and sorry for my english.
 
H

Homunculus

Guest
The reason I don't suggest upgrading exINV on existing projects, is mainly because the provided objects are meant to be used as a solid foundation for you to work on, or at the very least be extended by using inheritance, because I can't know in advance how you want your UI to behave or look. If you are already using exINV 1.4, chances are that you built a lot of stuff on top of that, and I simply have no way to provide an easy upgrade process for this.

If you REALLY want to access the few new functions, you could try updating just the core scripts, but you'll still have to update your objects code to account for some of the stuff that changed. If that's the way you want to follow, contact me in private so I can guide you.

About moving the panels with the mouse: i think that's outside of the scope of the asset. It should be fairly easy to implement yourself since slots are already set to follow the panel, but there's no single nor simple solution to manage object overlapping, it really depends on your project specifics.
I don't understand instead what you mean by "optimized for 2d platformer". The asset can totally work out of the box for any kind of 2d game requiring an inventory. Moreover, the inventory management and the UI are totally decoupled, so you are definitely not required to use the assets I provide for the UI
 
Last edited by a moderator:
C

Crysillion

Guest
It's a very real possibility that I'm just missing something here, but taking all of the ex folder scripts, objects, etc. as stated in the documentation guide seems to amount into a considerably buggy process that I cannot even begin to understand.

My game project is not very far along, so there's very little going on with it at its core. I grabbed exINV (for GMS2) because the Installation Guide seemed fairly straightforward. Bafflingly, my game crashes for a seemingly unending number of reasons whenever I try to run it with exINV installed and the very first step of the Installation Guide taken.

I'm finding issues with variables not being created before being read, I'm having issues with ds_grids not existing. I have no idea how to fix any of it or what is even going on.

I did step 1 of this Documentation outlined here: http://ekalia.com/gm/exinv/doc/

Importing was fairly straight-forward. I double-checked my project with the exINV demo project and everything is accounted for. So, if that's the case, I cannot understand why on merely doing Step 2, my game crashes:

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object o_game:

Data structure with index does not exist.
 at gml_Script_ex_db_load (line 11) -        var _width = ds_grid_width(_csv);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_ex_db_load (line 11)
called from - gml_Object_o_game_Create_0 (line 25) - ex_db_load("inv_armor.csv","inv_food.csv","inv_potions.csv","inv_weapons.csv");
OK, so here's the relevant bits of my Create Event in o_game:

Code:
//initialize and load the sample database csv files
ex_init();
ex_db_load("inv_armor.csv","inv_food.csv","inv_potions.csv","inv_weapons.csv");

//(optional) initialize the crafting system
ex_craft_init();

//create an inventory with 30 slots
global.inv_player = ex_inv_create(30);
So, right away, it's safe to assume the .csv files aren't in my project. But, they are. I put them in the Included Files section in an ex folder, just like the exINV demo project, so what gives? Why can it not find them?

I can absolutely see that this is just me, judging by the lack of other people having similar issues in this thread, so I accept that it's most likely not an issue with the asset or the developer, but some help would be nice in trying to figure this out.
 
Last edited by a moderator:
H

Homunculus

Guest
Hi! I'm sorry you are encountering problems importing the resources successfully into your project, unfortunately I can't find a better way to improve this process, but I'm definitely open to suggestions.

About your specific error, first of all, are you using the latest version (1.5) ? In the sample code of this version you'll see that the CSV files, being in an "ex/" folder, are loaded like this:

Code:
ex_db_load("ex/inv_armor.csv","ex/inv_food.csv","ex/inv_potions.csv","ex/inv_weapons.csv");
You have to provide the full path to the csv.

EDIT: I just realized that the documentation doesn't consider the files to be in a subfolder, which can be misleading and is probably why you are struggling with this. I already corrected the docs accordingly.
 
Last edited by a moderator:
C

Crysillion

Guest
Thanks. That's exactly what it was. I've never messed with databases before, so I didn't know if it being in a folder would've been a big deal - turns out that it was. I saw the Documentation edit and corrected my code according, I'm happy to say that now works.

However, I'm now running into another issue, or perhaps it's more of a misunderstanding as to how this program works. Your Documentation suggests taking a heavy look at obj_inv_controller and essentially how the demo manages to display the inventory as a whole. This feels like sound advice, so I took what seemed to be the necessary objects and placed them into my project from the demo directly - just so I could mess with some things here and there to really get a good grip as to how this system works.

The very first thing I encountered felt very strange to me. Loading up the game has the inventory open automatically, and I have to go and close it. I saw that this occurs through obj_inv_rm_controller. As you know, it runs code to create inventories and open them. I figured that most assuredly, opening it was more of a demo thing - so, that was the culprit. However, whenever I comment out the opening of the inventories or remove that code, the whole thing falls apart. It's unable to find variables because they aren't defined yet:

Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: User Defined 2
for object obj_inv_controller:

global variable name 'inv_equipment' index (100056) not set before reading it.
 at gml_Object_obj_inv_controller_Other_12 (line 15) - ex_ui_panel_show_layer(global.inv_equipment,obj_inv_panel_equipment,755,128,"inventory_panels");
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_inv_controller_Other_12 (line 15)
called from - gml_Object_obj_inv_controller_Step_0 (line 17) -               event_user(INV_CONTROLLER_EVENTS.open_toggable_inventories);
it all seems like everything obj_inv_rm_controller has is 100% necessary and non-optional in order for obj_inv_controller to function. Including having the inventory open when the game is loaded.

I apologize if this feels very silly to you, but I really just wanted to use the demo files and work backwards - removing things, see how they work, and ultimately mold the code to what I'm trying to accomplish - but I hit a wall when I try to understand how the code works and it seems like the code requires the inventory to be open at first in order to initialize properly, and even having code to close the inventory immediately after doesn't resolve anything.

More testing makes me think that the inventory automatically opens whenever I change rooms.

I feel like this stems from having the obj_inv_rm_controller be persistent. The code inside leads me to believe that it's not supposed to be persistent, as the note reads as follows:

Code:
/*
    Being the first room of a new game, we ask the inventory controller
    to create some fresh inventories for the player.

    Ideally, you want to do this only once at the beginning of a new game, since inventory data is persistent
    across rooms.
*/
However, if I remove the objects persistence, I run into issues with undefined variables whenever I try to open the inventory, so the object needs to be persistent, but I seriously cannot figure out why. The code makes sense to me - it defines these missing variables and that should be the end of it, but it's like the creation of these variables abruptly gets lost as soon as the room changes. I have this object placed in an init room, which then moves the player off to another room once finished.

I'm trying to go by your demo code as an example of good practices when using your asset, so I'm just trying to figure out how that code works to better understand it as a whole.
 
Last edited by a moderator:
H

Homunculus

Guest
The reason i "suggest" looking at obj_inv_controller is that every game has different inventory has different requirements and needs to be created / displayed / destroyed based on your needs, it can't be set in stone.

About your question:

Looks like you are commenting out too much from obj_inv_rm_controller. The lines you want to remove are these:
Code:
    //Open the static inventories (always shown)
    event_user(INV_CONTROLLER_EVENTS.open_static_inventories);
 
    //Open the toggable inventories
    event_user(INV_CONTROLLER_EVENTS.open_toggable_inventories);
The first line is required for the demo code to work:
Code:
event_user(INV_CONTROLLER_EVENTS.create_inventories);
just creates the inventory in memory, it doesn't actually show anything, so you should definitely not comment that out if you want everything else to work properly. You can of course remove that if you implement your own logic, but the demo code in obj_inv_controller assumes that when you are in the game room, the player inventories exist (even if they are not displayed or empty).


A few tips to help you understand how inventories in exinv actually work:

- You have to think of inventories as data structures (ds_lists, ds_grids, etc...). Like data structures, when created they hold data in memory, and it's kept in memory until you explicitly destroy it. Changing rooms does nothing to your inventory data, it will still be there. As data structures, losing every variable referencing to your inventory will cause the data to stay in memory as long as the program runs and can no longer be accessed, causing possibly memory leaks.

- Due to the above, you have to make sure you are not creating your inventories from scratch every time you change room. If you have already created your player inventories somewhere, you just have to reuse / reopen them. This is why you run into problems when making obj_inv_rm_controller persistent, since you are in fact creating NEW inventories every time the room changes, which is totally wrong.

- As an example, if you wanted to add a "second stage" room to the demo, all you have to do is create a new room and put obj_inv_controller inside (but not obj_inv_rm_controller). Add the two empty instance layers used by obj_inv_controller to display the inventories and you’re done. You'll see that your inventory is preserved after the room change (although you'll probably need to reopen it by pressing "I").
 
Last edited by a moderator:
C

Crysillion

Guest
Thank you for being patient and informative. I realize I'm being "that guy" right now, and I appreciate you trying to help most definitely.

One thing I wanted to say though was that I tried only commenting out what you said, the result was that the variables could not be found because they were not defined. I never commented out the code for creating the inventories.

As I said before, I see that it's creating the variables, but it's almost like when the player goes into a new room, those variables are suddenly no longer defined, which doesn't make any sense.
 
H

Homunculus

Guest
Can't really tell what's happening, I just tried that in the demo project and commenting out those two lines works, as well as using the inventories in a new room.

Make sure you are not trying to open the inventories before they are defined (consider that obj_inv_rm_controller creates them in the room start event, which executes AFTER the create event of every other instance), and that you didn't inadvertently comment out some relevant code in event_user_0 of obj_inv_controller.

EDIT: one thing to note is that inventories related to event_user(INV_CONTROLLER_EVENTS.open_static_inventories); in the demo do not have a key that opens them (since they open inventories that are always on screen). This includes the mouse interaction (since the mouse is an inventory too).
 
Last edited by a moderator:
C

Crysillion

Guest
Ahh, that's what I was overlooking. I have a tendency to forget that the Create event takes such precedence and it was exactly what the problem was. That solves it, then. Sorry about all that - in that case it really didn't have anything to do with your asset.

Thanks again.
 
C

Crysillion

Guest
Hey @Catan, I was working with your asset some more and looked through the documentation. I've learned how to do quite a bit of things with the asset, but one thing that eludes me is how to go about having the objects be drawn with Draw GUI.

The big thing is that I'm not even sure where the drawing actually happens to begin with. I tried to figure this out on my own by going through the scripts and checking through how you did it in the demo, but can't seem to quite grasp how it all works internally.

It's not to say I'm entirely clueless, plenty of things in your scripts do make sense and I've managed to make some adjustments to better suit what I'm trying to accomplish in my game without a hitch, but the drawing is hanging me up more than I thought it would, so I figured I'd go ahead and reach out to you here.

For instance, in your documentation it says to use ex_ui_panel_show_layer to draw the inventory, but I don't actually see this used anywhere in the demo. It makes me wonder how the demo example is doing it.

Thanks for reading, and I apologize in advance if this all seems rather annoying.

By the way, I do plan on creating an inventory "from scratch", so-to-speak, using what the Documentation teaches. I'm just trying to fully understand the intricacies of the demo example first, as the Documentation suggests that I take a good hard look at some of the code within, such as obj_inv_controller.
 
H

Homunculus

Guest
No worries, I understand that this is not the easiest system to grasp at first, but that's because I wanted it to be as flexible as possible.


About the draw events, since there's no one-fits-all solution for every game, I kept the example simple: all the drawing happens in the draw events. There are no "draw" scripts or anything like that, so that's all you need to look at. All objects (panels and slots) are drawn at their x,y coordinates (and follow the view). There's nothing fancy going on there. There are two things to note thugh:

1. When you open or close a panel using ex_ui_panel_show_layer / ex_ui_panel_hide (those are used in obj_inv_controller in the toggle UI events), you may expect the inventory to be hidden / displayed using "visible" or a draw condition, but it's not. I'm actually creating / destroying the panel and its slot instances every time. It's not a "draw" operation.

2. The sprite for the slots is set in obj_inv_slot -> user event 1. This event is automatically called every time the inventory slot changes and needs to be updated. The actual draw happens in the draw event.

It should not be too difficult to convert the above from regular draw to draw gui, but you'll have to keep in mind that to interact with the inventory using the mouse the slot and panel objects need to be at the right position relative to the view in any case.

If the GUI resolution is different than the game resolution though, things get a lot more complicated, but that has not much to do with the inventory system itself, there are a few resources out there showing how to design objects you can interact with in a case like this.
 
Last edited by a moderator:
C

Crysillion

Guest
I read all what you said, but I did want to throw out there that I tried changing all of the Draw events in your codes to be Draw GUI instead and ended up getting some weird situations where the inventory was being drawn with Draw and Draw GUI simultaneously (or that's what it seemed like), and in one case the Draw GUI was being drawn twice on two seperate Y axis locations. That's why I said I couldn't quite figure out how the objects were being drawn, because simply changing them over to Draw GUI resulted in a considerably buggy output.

Understanding that hide/show is actually destroy/create does help things a bit.
 
H

Homunculus

Guest
You can't expect a transition from Draw to Draw GUI to work without actually changing anything (under any circumstance, not just in this asset). The minimum you are required to change is the x,y coordinates where the stuff is drawn, since they are no longer relative to the room but to the window instead.
 
C

Crysillion

Guest
I feel like at this point I might be hassling you with general knowledge questions that aren't specific to your asset per se. I'm going to confess my lack of knowledge on some of the coding you've used and focus on other things on my project for now until I can better learn GML. Thanks for your help, I'll probably stop by in a couple weeks or so when I'm able to better understand.
 

SkyKnight

Member
Trying to use this system in a terraria way at the moment. As in, what ever slot is highlighted in our tool bar is what our left click or right click will use. I contacted the publisher early today and in my time working with the code have had some successes. ... I have gotten to the point where I can middle mouse button a tool bared item and make an effect happen. But cant make the jump yet from using the tool bar or even equipped item (like in the sword slot lets say) to what happens when we want an effect or attack for our toon or what ever.



I think what I will need to do is have an event that calls on the slot number (or what slot we have highlighted), checks the item ID and based on the ID runs a code ... Such as, we know for left click we have a sword in our weapon slot so when I left click the player object checks the ID and uses what ever weapon we have. But when we right click we check to see what we have highlighted in our tool bar, Oh was it a healing potion, run the script that heals us. ... But HOW to do that I have no idea where to start hehe. Just wanted to know if anyone had figures this out? I am super noob at coding just fyi so I may have a hard time understand.

Thank you for your time : )
 
Last edited:
H

Homunculus

Guest
It shouldn’t be too difficult to implement.

First of all, you need to add to each item the information about the script that needs to be run when used. You can do that by writing the script name in the database (the csv files) in a column of type “asset”.

Then you need to work on your hotbar panel. By default, exinv treats right click as “take/release half of the stack”, so you need to override that event in the hotbar object, and instead just get the item script from the item database and execute it with script_execute.

That’s the general idea, if you have any doubt about the specifics just ask.
 

SkyKnight

Member
Thank you Catan. I'm pretty sure its that I have had a long day and I have only spent maybe two hours or so looking at this but I will ask about specifics if you don't mind.

So first off I have gone in to the Datafiles/ex and opened the csv file for potions. I have added a 8th column and called it an asset and for potion_health have told it to use "scr_healing". At the moment the code for that is empty but I'll do something with it like close the game or such if it works, its just to test so I can understand how to use this.

Now I have gone in to GMS and have opened the "obj_inv_panel_toolbar" and I see the left click, override ... and I am drawing a blank at this point... I know we will be using a if mouse_check_button(mb_left) (or right) then checking the item in the slot we are currently selected and telling it to run its code. But I have no idea how. I feel like I also may need to add some variables before hand to get this to come together.

So the specifics of this are... IN our obj inv panel toolbar, left click event. How do we check selected panel, what item we have in that panel and run its code.

Again- I know I'm a noob so I am sure this is not that difficult but its a bit over my head. Thank you again for your time Catan.
 
H

Homunculus

Guest
First let me clarify something I probably got wrong from your first post: do you want an item to be used when clicked with right mouse button, or do you simply want to use the selected it when the right button is pressed anywhere on the screen?
 

SkyKnight

Member
When I was writing down the ideas on paper my thought was that we would have a hot bar at the bottom of the screen and based on what I had selected (What was highlighted) when we would left click our player object would do an action based on the item. ... So ... lets say we had a sword in slot one and a potion of cold in slot two (looking at the tool bar from left to right). Now our player object needs to break down some wood door. We click 1 and we now highlight the first slot where we had our sword. Now when I left click on the screen I'll run a sword animation and spawn a hit block for the sword in the direction of the mouse. ... Now that the door is gone we have some water in the next room and I want to freeze it to walk across. So I hit the number 2 and this brings us to our second slot that has the potion of cold. Now when I click on the screen we throw the potion something like Mario would throw a boom or link would throw a pot. It goes in the direction of the mouse (from the player object) and breaks after an alarm timer and freezes water blocks. ... now we can walk over it.

So- In my original plan I did not have a weapon slot but you have something like that in your exINV. Not sure if I will use that or not but if I did, Left click would always check and use the weapon slot and make a move based on player object and mouse position, right click would always check what slot in the tool bar was highlighted, what the item is in that slot and run a script based on that item. So our hero here would have had a sword and just left clicked to break down the wooden door, seen the water in the next room and moved the highlight to the cold potion and right clicked towards the water to throw it and freeze it.

Thinking about it now with a little more sleep I think that the player object may need a left and right click check that calls for whats in our weapon slot and our selected slot for the tool bar and runs its code.
 
Last edited:
H

Homunculus

Guest
If that's the case, you are right, you probably want something like and equipment inventory with named slots you can refer to. The sample project shows just that. The only thing you'll need to consider is differentiating a left/right click used for attacking / using an item from a click used for moving stuff around in your inventory (or using any other UI element).
 
O

oudin.chen

Guest
How to use the arrow keys to select the obj_inv_panel_backpack item
 
Top