Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Slimenian · Jun 15, 2016 at 06:18 AM · c#arraylisthowmultidimensional array

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Jun 15, 2016 at 03:19 PM 0
Share

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?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Jun 15, 2016 at 09:21 PM 0
Share

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.

avatar image Slimenian Owen-Reynolds · Jun 16, 2016 at 08:06 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges