I am trying to develop a grid inventory system where items can occupy multiple slots and have various shapes (such as L, T, and I).
Currently, I am attempting to implement a function called canPlaceItem, which checks if an item can be placed at a specific position in the grid. The function should:
- Receive the coordinates (startX, startY) of where the item is being placed.
- Check if the corresponding cells in the grid (arrayInventoryGrid) are occupied (i.e., not empty).
* System: On start of layout
-> itemL: Set value at (0, 0) to 1
-> itemL: Set value at (1, 0) to 1
-> itemL: Set value at (1, 1) to 1
-> arrayInventoryGrid: Set value at (0, 0) to 1
* On function 'canPlaceItem'
* Parameter 'startX' (Number)
* Parameter 'startY' (Number)
----+ itemL: For each XY element
--------+ System: itemL.At(itemL.CurX,itemL.CurY) = 1
--------+ System: arrayInventoryGrid.At(startX + itemL.CurX, startY + itemL.CurY) = 0
---------> debug: Set text to 0
--------+ System: Else
---------> debug: Set text to 1
+ Mouse: On Left button Clicked on slotInventory
-> Functions: Call canPlaceItem (startX: slotInventory.id % numColunas, startY: floor(slotInventory.id ÷ numColunas))
The canPlaceItem function always returns that the slot is free, even when I click on a slot that is occupied. Debugging the value of arrayInventoryGrid, I notice that it is not returning the expected value (0 for free slots and a non-zero value for occupied slots).
Can anyone help me understand why the check for occupied slots is not working correctly? Any suggestions on how to improve this logic or additional debugging steps I could add to identify the problem?
here is the c3p file: drive.google.com/file/d/12WkZ9h_QeEKsr2BtISrKjGmkV8_jO2DY/view