adding an additional variable to a bracket

8 ビュー (過去 30 日間)
Shane Gibbs
Shane Gibbs 2019 年 1 月 4 日
編集済み: Bob Thompson 2019 年 1 月 7 日
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.)
madhan ravi
madhan ravi 2019 年 1 月 7 日
+1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by