adding an additional variable to a bracket

4 次查看(过去 30 天)
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 :)

采纳的回答

Bob Thompson
Bob Thompson 2019-1-4
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.
  4 个评论
Bob Thompson
Bob Thompson 2019-1-7
编辑:Bob Thompson 2019-1-7
Accepting the answer, and the vote are more than enough.
I appreciated the 'uniqueness' of your project. If you need any other help, feel free to comment further on this question, or just link to the code on the file exchange so I can read any commented questions you might have added.
(Edit: Apparently PMs aren't a thing on this forum.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by