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 DJohn90 · May 31, 2013 at 12:31 PM · arrays#pragma strictbuiltin array

Converting to Builtin Array for #pragma strict in javascript

Hi All

How do I convert this js script to be #pragma strict friendly?

I keep getting the error the 'Object' does not support slicing. So I understand that the object in the array should be predefined to a string so that when it is pulled out the program knows how to treat it. All my efforts have failed please help:) Thanks!

 scores = new Array();            // All scores are in this array - new is used to reset array
             
             scores.Push(new Array());        // Create a new array in a array
             
             // scores => new array
             scores[0].Push(new Array());    // Now add another array in to the 0 index place of an last array, this array has index 0
             scores[0].Push(new Array());    // Now add another array, this array has index 1
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - Time","9999.99"));        
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - Name","New Player"));
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - i",""));
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - q",""));
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - a",""));
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - c",""));
             scores[0][1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - k",""));
Comment
Add comment
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

2 Replies

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

Answer by Eric5h5 · May 31, 2013 at 01:45 PM

Don't ever use the JS Array class. Only use built-in arrays or generic Lists; that way there won't be issues with casting, plus built-in arrays and Lists are faster and have more features.

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 DJohn90 · May 31, 2013 at 01:50 PM 0
Share

Hi Eric I've seen you post this before in other related questions, but the problem is i have all my playerpref write/reads in this array format and i'd like to keep using arrays if possible. As you say, to get it in built-in format will be better and #pragma friendly.. but i'm struggling mate..

avatar image Eric5h5 · May 31, 2013 at 01:54 PM 0
Share

You really need to get rid of Array. It's quite simple to convert Array to List; see the link I posted for some more info.

avatar image DJohn90 · May 31, 2013 at 02:01 PM 0
Share

i'll have a read. Will this definitely work with #pragma strict? cheers

avatar image Eric5h5 · May 31, 2013 at 02:04 PM 0
Share

Yes, the point of generic Lists is that they can only use a particular type.

avatar image DJohn90 · May 31, 2013 at 02:20 PM 0
Share

got it working with generic lists. Now to convert the other 2000 lines:( Thanks mate!

Show more comments
avatar image
0

Answer by PAHeartBeat · May 31, 2013 at 01:00 PM

try this

 scores[0,0] = new Array();   // Now add another array in to the 0 index place of an last array, this array has index 0
 scores[0,1] = new Array();   // Now add another array, this array has index 1
 scores[0,1].Push(PlayerPrefs.GetString("sc"+cp.ToString()+" -"+lvl.ToString()+"-1 - Time","9999.99"));
Comment
Add comment · Show 1 · 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 DJohn90 · May 31, 2013 at 01:54 PM 0
Share

thanks PAHeartBeat but how do I read from from this? Currently, I use this code to read from my score playerprefs:

 var time =    scores[0][1][0];
    var playerName =    scores[0][1][1];
     //etc

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

15 People are following this question.

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

Related Questions

Checking what slot in a built-in Array my gameobject is in 1 Answer

Array elements change Gameobject.tag 1 Answer

Help with #pragma strict Arrays? 1 Answer

Distance error: Cannot cast from source type to destination 0 Answers

Can I change inspector 'Element 0' to something else? 6 Answers


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