Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by timsk · Feb 21, 2012 at 05:58 PM · serializationmultidimensional arraydatastructure

Best way to match up 3 bits of data

Hi Everyone, Sorry about the vague title. I couldn't think of anything better.

At the moment I'm creating a level selection menu, currently I'm storing the level information in arrays:

 var levelsList : String[];
 var levelsPictureList : Texture2D[];
 var levelsDiscriptionList : String[];

Now the problem with this is we have to manually check that the array indexes match up(so index 0 in each array corresponds to the data for level 1 etc.). I can already tell that this is going to cause issues for us later on.

My question really is; How would I store 3 data types in the same Object, and be able to easily access each bit of data seperately?

I've been looking into multidimensional arrays, which is not something I've used before. Is this the way forward? If so, any pointers on how to best use a 3d array?

I was also thinking about Serialization. Again, not something I've used before, would this be appropriate for what I'm trying to achieve? I'm totally new to serialization, so if this is the best option I might need some guidance :(.

Comment
Add comment · Show 2
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 by0log1c · Feb 21, 2012 at 09:12 PM 0
Share

I'm currently at work but you definitly want to learn about classes. Look on the forums for the Newbie Guide to Unity Javascript, you could learn something useful :)

avatar image timsk · Feb 22, 2012 at 09:20 AM 1
Share

Seems that way, time to get my reading hat on.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Feb 21, 2012 at 09:23 PM

You should make a class:

 class LevelData {
     var name : String;
     var picture : Texture2D;
     var description : String;
     
     function LevelData (name : String, picture : Texture2D, description : String) {
         this.name = name;
         this.picture = picture;
         this.description = description;
     }
 }

Then:

 var levelData = new LevelData[10];
 levelData[0] = new LevelData ("Level1", level1pic, "The first level.");

For more information see JScript.NET classes. You can also look up C# classes since it's mostly the same.

Comment
Add comment · Show 8 · 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 timsk · Feb 22, 2012 at 09:27 AM 0
Share

Edit: Ok, read up a bit. Looks like this is a construct, right? I'm guessing you can't edit this sort of thing in the editor by default?

avatar image Eric5h5 · Feb 22, 2012 at 10:06 AM 0
Share

A construct? No, it's a class. And yes you can edit it in the editor. You don't have to do anything, it just works by default (unlike C# ;) ... response to comments on the other answer).

By the way, I tried to edit the answer to correct the code (should be "var name : String, var picture : Texture2D, etc.). But it seems editing doesn't work anymore.

avatar image ZweiD · Feb 22, 2012 at 10:17 AM 0
Share

give the edit a couple of hours to show up, last time i edited something it needed that long to show up as well -.-

that is kinda weird (the working by default in unityscript and not in c#) because as i understand it, it shouldn't matter at all what language you use, right?

avatar image Eric5h5 · Feb 22, 2012 at 10:25 AM 1
Share

http://unity3d.com/support/documentation/ScriptReference/Serializable.html

avatar image ZweiD · Feb 22, 2012 at 10:33 AM 0
Share

ah ok, so it isn't really a problem after all. Just add the attribute and you are good to go. thx for the link

Show more comments
avatar image
-1

Answer by ZweiD · Feb 21, 2012 at 06:04 PM

do it like this:

 var levels : Object[];

and store the level-Object like this:

 levels.push({
     name: 'level1',
     picture: new Texture2D(),
     description: 'the first level'
 });

Then you can access the information like this:

 levels[0].name
 // or
 levels[0]['name']

disclaimer: don't know if that works in unityscript, only know it works in javascript

Comment
Add comment · Show 6 · 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 asafsitner · Feb 21, 2012 at 07:15 PM 0
Share

UnityScript is JavaScript. Or, to be more accurate, a modified version of traditional JavaScript.

avatar image Eric5h5 · Feb 21, 2012 at 09:21 PM 0
Share

Not really; Unityscript isn't much like Javascript at all. It's more like ActionScript3 or JScript.NET. For example, the code in this answer won't work at all I'm afraid.

avatar image ZweiD · Feb 22, 2012 at 08:47 AM 0
Share

ok, but why the down vote?

the basic principle still applies and I said that I am not sure the code does work.

what you are doing is basically the same thing that I do, just a bit more verbose.

avatar image timsk · Feb 22, 2012 at 09:13 AM 0
Share

Thanks for the answer ZwieD. I had no idea you could declare type "Object" though, so it wasn't all a waste :).

The argument of what UnityScript is exactly seems as old as Unity itself. I remember reading an official description from UT somewhere, might be worth looking for it.

avatar image ZweiD · Feb 22, 2012 at 09:45 AM 0
Share

You are welcome.

that's why I'm using C# and not unityscript, as it seems kinda unclear what you can and what you cannot do (compared to javascript).

I don't really see a point in using unityscript if you loose all of the flexibility of javascript (like in my example: providing an object on the go without first declaring a class / struct) and have to use a more verbose syntax.

But that may only be me because I like 'wrestling' with javascript sometimes ;)

Show more comments

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

9 People are following this question.

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

Related Questions

Serialize custom multidimensional array from Inspector 3 Answers

How to make custom 2 dimensional enum array class 1 Answer

How do you work with multi-dimentional arrays 2 Answers

Save/load playerprefs 2 Answers

Saving/Load using menu C# 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