adding an additional variable to a bracket

9 visualizaciones (últimos 30 días)
Shane Gibbs
Shane Gibbs el 4 de En. de 2019
Editada: Bob Thompson el 7 de En. de 2019
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 :)

Respuesta aceptada

Bob Thompson
Bob Thompson el 4 de En. de 2019
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 comentarios
Bob Thompson
Bob Thompson el 7 de En. de 2019
Editada: Bob Thompson el 7 de En. de 2019
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 el 7 de En. de 2019
+1

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by