• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Issue with Inventory & DS_Grid

S

SRJProd

Guest
Heya,
I've spent the past two days looking for a solution to this so this is really my last desperate measure. x)
Three days ago I started following Friendly Cosmonaut's Farming RPG tutorial series and all went (mostly) smoothly. But now I've run into a problem that (search as I might) I can't seem to solve. So far every time I ran into an error I managed to find the solution (even if frustration occurred) and after all, finding solutions to problems is what programming is about. But in this situation I don't know what to look for.

The issue (or issues, there are really 2, though I think they're probably linked) are as follows:

  • In the inventory everything works fine except the top left item which cannot be grabbed, nor can any item of the same type anywhere else in the inventory. (Say the item in the top left is a potato, I won't be able to select any potatoes)
  • The second issue is that when I drop an item, when I go to pick it up, if I don't have the item already in my inventory it sends me "Grid 4, index out of bounds writing [0,16] - size is [2,16]" in the Output and the item just hovers by my player's feet.

I re-watched the videos, compared the code, even googled the issue, nothing.
So as to not clutter the page I uploaded the source code to pastebin:
inventory - Create Event : pastebin.com/6b2JHRfV
inventory - Draw GUI : pastebin.com/wakPFMLf
inventory - Step Event : pastebin.com/emyvGEm2
Note that "inventory" is the object's name.

For reference here's a link to the tutorial series I was following.



Really hope someone can help,
Thanks in advance and best regards,
Sebastien​
 
The error message is a great help here. Your grid is out of bounds as you're trying to write to the 17th location height; when you created it you only created 16 height.

You can work through your code and identify when it is trying to add out of bounds. It may be you want 17 height in which case just increase size of ds grid. :)
 
S

SRJProd

Guest
Thanks, I sort of understood that. I think the biggest issue is a lot of the grid accessing and writing is done in repeat statements. So I've been finding it really hard to fix. I'll look through it again a soon as I have the time.

Thanks :)
 
S

SRJProd

Guest
Btw, the DS grid should automatically adapt to the size of how many items are in the game. It's made to be flexible, so manually changing it would probs be a bit foolish x)
 
S

SRJProd

Guest
At this rate it might be quicker just to redo the inventory from scratch, feels like looking for a needle in a hay stack.
 
The grid won't resize unless you tell it to with a grid resize - I've only skimmed your code but couldn't see that you did this?

If you run in debug, you can pinpoint the exact line of code where the error occurs and work from there.
 
S

SRJProd

Guest
Ok, so I also got a reply from Friendly Cosmonaut (whom I'd contacted on Patreon) and she found the first problem.
In the inventory on one line I had written "else if(ss_item != inv_grid[# 0, 0]){" when I should have been running "else if(ss_item != item.none){" (I was essentially checking that it wasn't the first slot, rather than if the slot was empty :rolleyes:)

The second problem was actually in another instance the item instance (which I hadn't even thought to check until she mentioned it, so I feel pretty silly about that).
I was essentially not resetting a variable between two repeat statements so it just incremented higher than the limit in the second one (the one checking for empty slots).

Thanks for your help Michael Bateman,
I'm glad to set this post as solved :)
 
Top