Hello, I working on inventory for survival game. But i just don’t know how to make this system universal. Because right now my “system” need code for each slot. I mean if you will have 10 slots you need to write compability with every slot for every slots. How my inventory looks right now:
I wanna get something like this:
Can you please explain how this systems works, without snapping or anything, just basic knowledge.
First of all, you’ll need a detection system to check if the mouse is inside a slot or not, you can do that by iterating through every single slot in the inventory and writing some functions with .MouseEnter and .MouseLeave
For the mouse, check when it’s pressed and it’s touching a slot, then check when it’s unpressed and if the slot the item’s getting dropped in has already one or not
I did that, but I have problem. I need the slot to automatically detect and put the thing into itself when the frame is released. But I have not idea how to make this for each slot automatically. I used :GetGuiObjectsAtPosition to detect which slot was on my cursor when I released mouse. I already tried MouseEnter but it’s not working because of multiple frames at cursor.
You should have a variable in your script that describes what slot your mouse is touching
when using MouseEnter, change that variable to the slot. When using MouseLeave, check if the mouse is in the same slot or if it’s in another one, if it’s in the same one, set the variable to nil. This is to prevent setting the variable to nil when the mouse has touched another slot
I can’t make mouse enter thing, because I dragging frame same time and mouse enter not working because of this. My dragging item frame just blocking mouse enter. I can only detect something when mouse released.
I got some progress, I still not using mouse enter way. But I maked table with slot name and boolean (empty or no). Now its working without glitches. But its still need to be upgraded.
Its has currentlyDragging variable, which have value “”, and “(Currently Dragged slot)”. When slot dragged script inserts currently dragged slot name in this variable.