What is the uncommon herb medicine code you mention, you didn't share this? This looks a bit convoluted for adding an item to an array, do you definitely need to use dictionaries?
You could store an item as a global variable string and use that to add in the array. You can run a basic 'for' loop from 0 to array.width to find the next empty X and store that somewhere to make sure it's working and finding the correct row.
Once that is confirmed you can then try adding the item to that row and confirm that is working. Also since you are using a function, you could find the dictionary item required outside of the function and pass it through the function as a parameter to also check it.