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 Cataclysm Entertainment · May 24, 2014 at 09:04 PM · listarrayssavegetstring.split

Saving or get array of string - PlayerPrefs

Hello world,

I would save and get list, using an array (of course), by PlayerPrefs but it doesn't work, or unity doesn't recognize my scirpt, i've a lot af compiler errors.

Please note that I not use the PlayerPrefsX/ArraysPrefs2 - I prefer use my own script cause I prefer improve me to scripting.

Here's my script :

 #pragma strict
 import System.Collections.Generic;
 import System.Collections;
 
 public var ItemList : List<ItemArray>;
 public var CheatCodesList : List<CheatCodeArray>;
 var CheatCodeArray : String[];
 var ItemArray : String[];
 
 function GetItemList () {
 
     var readLine : String = PlayerPrefs.GetString("Items");       
        
        ItemArray = readLine.Split("*"[0]);
     
 }
 
 function GetCheatCodeList () {
 
     var readLine : String = PlayerPrefs.GetString("Items");    
        
        CheatCodeArray = readLine.Split("*"[0]);
  
         //for(var i : int = 0; i < readArray.Length; i++) {
         
             //ItemList = readArray;
             
         
         //}
     
 }
 
 public function SaveItemList () {
 
     var temp : String = "";
  
     for(var i : int = 0; i< ItemList.Count; i++) {
     
         if (i != ItemList.Count - 1)
         
             temp += ItemList[i].ToString() + "*";
                                    
         else
         
             temp += ItemList[i].ToString();
     }
     
     PlayerPrefs.SetString("Items", temp);
 
 }
 
 public function SaveCheatCodeList () {
 
     var temp : String = "";
  
     for (var i : int = 0; i < CheatCodesList.Count; i++) {
     
         if (i != ItemList.Count - 1)
         
             temp += CheatCodesList[i].ToString() + "*";
                                    
         else
         
             temp += CheatCodesList[i].ToString();
     }
     
     PlayerPrefs.SetString("Items", temp);
 
 }

Thanks for avcande

Comment
Add comment · Show 5
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 fafase · May 24, 2014 at 09:20 PM 0
Share

It seems your list are not initialized only the reference is declared. What are your errors?

avatar image fafase · May 24, 2014 at 09:22 PM 0
Share

Also, I think in UnityScript, list declaration takes a . :

 var list : List.<Type>();
avatar image AlucardJay · May 25, 2014 at 03:25 AM 0
Share

Declare :

  var list : List.<Type>;

Initialize :

  list = new List.<Type>();

One-Liner :

  var list : List.<Type> = new List.<Type>();

note the full-stop (period)

http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?#Generic_List

avatar image Cataclysm Entertainment · May 25, 2014 at 09:51 AM 0
Share

I do it, but Unity doesn't recognize my type in the list :

 #pragma strict
 import System.Collections.Generic;
 import System.Collections;
 
 public var ItemList : List.<ItemArray> = new List.<ItemArray>();
 public var CheatCodesList : List.<CheatCodeArray> = new List.<CheatCodeArray>();
 public var CheatCodeArray : String[];
 public var ItemArray : String[];
 
 function GetItemList () {
 
     var readLine : String = PlayerPrefs.GetString("Items");       
        
        ItemArray = readLine.Split("*"[0]);
     
 }
 
 function GetCheatCodeList () {
 
     var readLine : String = PlayerPrefs.GetString("Items");    
        
        CheatCodeArray = readLine.Split("*"[0]);
     
 }
 
 public function SaveItemList () {
 
     var temp : String = "";
  
     for(var i : int = 0; i< ItemList.Count; i++) {
     
         if (i != ItemList.Count - 1)
         
             temp += ItemList[i].ToString() + "*";
                                    
         else
         
             temp += ItemList[i].ToString();
     }
     
     PlayerPrefs.SetString("Items", temp);
 
 }
 
 public function SaveCheatCodeList () {
 
     var temp : String = "";
  
     for (var i : int = 0; i < CheatCodesList.Count; i++) {
     
         if (i != ItemList.Count - 1)
         
             temp += CheatCodesList[i].ToString() + "*";
                                    
         else
         
             temp += CheatCodesList[i].ToString();
     }
     
     PlayerPrefs.SetString("Items", temp);
 
 }

Here is the error : Assets/Player/Scripts/Warehouse Player/WarehouseHoster.js(6,63): BCE0018: The name 'CheatCodeArray' does not denote a valid type ('not found').

It's the same 2 times for the 2 list.

avatar image AlucardJay · May 25, 2014 at 02:51 PM 0
Share

A Type is not a variable, it is a component, class or script.

I cannot see anywhere you are using the list anyway (it is really hard to tell what you are trying to do). It seems you are trying to read the split string, which is stored in the arrays, not the List.

0 Replies

· Add your reply
  • Sort: 

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Strategy for saving game 1 Answer

A node in a childnode? 1 Answer

How do I save and retrieve ordered data? Can I do this with an array? 1 Answer

ReadLine to a Variable 2 Answers

Instantiate to temp var or directly adding to list? 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