adding an additional variable to a bracket
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shane Gibbs
le 4 Jan 2019
Modifié(e) : Bob Thompson
le 7 Jan 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:
- Gold Sword- +3 damage
- Titanium Sword- +8 damage
- Overseer Breastplate- + 4 armour
- 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 :)
0 commentaires
Réponse acceptée
Bob Thompson
le 4 Jan 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 commentaires
Bob Thompson
le 7 Jan 2019
Modifié(e) : Bob Thompson
le 7 Jan 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.)
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!