How to make multiple variables equal a class?
显示 更早的评论
Hello!
I need some help with trying to make multiple variables equal a 'class.'
I started using MatLab 2-3 months ago, so I am not very good at it.
I am currently making a menu-based RPG game, and I need to make an "equipped" screen.
What I am having trouble is making multiple variables = 1 "class"
For example...
Swords = (Bronze sword, Steel sword, Diamond Sword)
Helmet = (Bronze Helmet, Iron helmet, dark helmet)
Leggings = (Bronze Leggings, Iron Leggings, Stone Leggings)
and so on.
This way, I can prevent users from equipping a sword into a helmet slot, or prevent a legging item from equipping to a weapon slot.
I apologize if this is confusing.
Thank you so much! I will attach a copy of the game for assistance, or if you would like to play it.
采纳的回答
更多回答(1 个)
Take A Look At classdef documentation
Also Worth mentioning That For Proper Polymorphic Behaviour In Matlab, your Base class Needs To Inherit matlab.mixin.Heterogeneous
Then You Can Also Use the isa Function To Test If An Object Is Of A Specific Type Or If It's Of A Subclass Of That Type
类别
在 帮助中心 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!