MATLAB: Adding an additional variable to a bracket

bracketschanging variablesinventory

Hello!
This is my first time asking a question here, as I only started using MATLAB for about 2-3 months.
I am currently making a videogame using a menu format.
My issue is making an inventory system.
What i would like is to have a bracket of variables, starting with zero. However, as the story progresses, you will gain items in your inventory, either by getting them in dungeons, or in the shop.
Example:
In the Beginning:
Inventory:
no Items in inventory
But later on…
Inventory:
  1. Gold Sword- +3 damage
  2. Titanium Sword- +8 damage
  3. Overseer Breastplate- + 4 armour
  4. Wraith- +5 speed
I apologize if this sounds confusing. I can upload what I currently have in the game, but I dont believe it will be useful.
Thank you so much!
P.S. if you are playing the game, the code for Dragon Lord is 1122332211 🙂

Best Answer

I'm a little confused at what the problem is exactly. Would you be willing to explain a little bit more about what exactly you have tried?
I only glanced over your code, so I don't know intimately what is included, but you can create a variable called 'inventory' that can contain strings for the different item titles. This would allow you to store it all in one location, and then displaying just requires and if statement for a blank inventory.
if ~isempty(inventory)
empty = sprintf('Inventory:\n Whoops, it looks like your inventory is empty. You should probably fix that.');
LOL = menu('%s',empty);
else
format = repmat('%d. %s\n',1,length(inventory));
full = ['Inventory: \n',format];
LOL = menu(full,[1:length(inventory)],inventory);
end
I have not tested this, and I suspect it will take some finessing, but it should at least get you started.