2D Arrays Help. Why to use 2D arrays for 2 ints
Hello,
I have been learning unity & programming with a help of someone. He gave me some exercises to do but I am little confused on a certain task. First of all I need to tell you what I am making. He gave me a task to make stats for and RPG like game and to see them in the inspector, by using lists, so I can store each players stats.
I have some variables i setup: Examples: CurrentHP, maxHP, name, currentLevel, maxLevel, currentMana, MaxMana....
I am confused beacuse he said to put:
curHp,maxHp
curMana,maxMana
curXp,maxXP
curLevel, maxLevel,
into 2D Arrays. But i do now know why I should put them in 2D Arrays.
I don't know why I should put them into 2D arrays instead of normal arrays. Maybe so we can track where players health is from 0 to max?
Thanks for help,
~Slimenian
Sounds like a wax-on/wax-off type deal. When you can balance a tack hammer on your head, you will head off your foes with a balanced attack. That sort of thing.
$$anonymous$$aybe the guy just likes 2D arrays?
Answer by Blue-Cut · Jun 15, 2016 at 03:57 PM
Hello,
Someone correct me if I am wrong, but the answer is :
There is no worldwide reason why you should put these variables in 2D Arrays. The only difference is that instead of accessing each variable with its variable name, you can accessing it through the array, with indexes. Maybe your guy has coded a way where indexes are more convinient for him.
The best thing to do is asking him directly.
Answer by markdavidmorris · Jun 15, 2016 at 04:04 PM
If you always know you'll have the current value in column 1 and the max value in column 2, then having a n Nx2 array can be convenient. This way if you know the row index of the data you want to retireve (i.e. 2 for XP), then you can easily get the associated data (current or max value in this case).
But that's not especially useful. Health[p][0]=Health[p][1];
vs. Health[p]=$$anonymous$$axHealth[p];
. Arrays are good for items meant to be used in the same way, where the index can "pick" one of them. It's not like you're going to loop through current then maximum health (but you might loop through all stats, maybe to display them.)
$$anonymous$$aybe the idea is there're several players, and the stats are meant to be interchangeable for some purposes. 4 players with 6 stats each is a 4x6 array, sort of.
Well, the plan is to store data of each player like an online game. Character one: $$anonymous$$age Level 5 hp 525...., Character two: warrior level 29 Hp 1255....., Character Three...... So we can store each players data, so when the player chooses a Character that he saved all his data is also saved.
I also asked the guy who is helping me.
Your answer
Follow this Question
Related Questions
Array with pushing values? 0 Answers
Array (List) with multiple variable types? 2 Answers
Assign role randomly from array for my online game 2 Answers
How to declare a list of arrays? 1 Answer
[Quiz Game] How to prevent Question asked twice. HELP 1 Answer