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 twoface262 · Dec 15, 2012 at 04:20 AM · androidjavascriptfile-io

Load function not working propperly?

Here is my load function

  function load1(){
     var sr = new File.OpenText("Saves/planets.txt");
         var fc = sr.ReadToEnd();
         sr.Close();
         var planets = fc.Split("---"[0]);
         for(pla in planets){
         var lines = fc.Split("\n"[0]);
         for(line in lines){
         Debug.Log(lines[1]);
         x1 = parseInt(parseFloat (lines[1]));
         x3 = parseInt (parseFloat(lines[3]));
         }
         planet = Instantiate (ast, Vector3(x1, x2, x3), Quaternion.identity );
         }
     
     }

The problem that I'm facing is that will only load one planet. When there will be multiple one's in the file. Each one is split by "---" and it's suppose to be splitting those in the load function. What am I doing wrong here?

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

1 Reply

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

Answer by whydoidoit · Dec 15, 2012 at 06:35 AM

You can't split on "---" you are actually splitting on "-" with that line of code because the [0] just takes the first element of the string.

The easiest thing is probably to convert the "---" to a single character if there is one that can't be a part of the input - so something like:

 var fc = sr.ReadToEnd().Replace("---","`");
 var planets = fc.Split("`"[0]);
Comment
Add comment · Show 13 · 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 twoface262 · Dec 15, 2012 at 06:25 PM 0
Share

It's still only spawning one. When there are at least 5 saved in the file

avatar image whydoidoit · Dec 15, 2012 at 06:38 PM 0
Share

Right your other problem is that you are still getting the lines from fc not from planets - you need to make it:

  var lines = pla.Split("\n"[0])
avatar image twoface262 · Dec 15, 2012 at 06:41 PM 0
Share

IndexOutOfRangeException: Array index is out of range. saving.load1 () (at Assets/saving.js:114) saving.Update () (at Assets/saving.js:21)

114: x1 = parseInt(parseFloat (lines[1]));

avatar image whydoidoit · Dec 15, 2012 at 06:45 PM 0
Share

Well I'm guessing your file format has an instance where there are less than 2 lines in a section (or at least what it has managed to parse). I'm also not sure what the for next loop is doing over the lines collection as you appear to ignore it and just take a value out of the array irrespective of the line you are on.

Perhaps if you could post a couple of entries from your file it might be easier to spot.

avatar image twoface262 · Dec 15, 2012 at 06:47 PM 0
Share

Here are two entries from the file -


1610.388

1241.892

Laose429

100

RGBA(1.000, 0.902, 0.000, 1.000)

0

0

1

0

0

null

5524

133

133

244

244

0

746

0

null

1

1

0

476

sun (UnityEngine.Transform)

9

0

131

0

601

22

5

10

(0.0, 0.0, 0.0)

0

(1610.6, -476.0, 1241.6)

null

134

610

394

6

1

(0.0, -0.3, 0.0, 1.0)


574.2449

1201.469

Altar295

100

RGBA(1.000, 0.483, 0.000, 1.000)

0

0

1

0

0

null

5304

132

132

254

254

0

613

0

null

3

1

0

476

sun (UnityEngine.Transform)

6

0

128

0

472

18

5

10

(0.0, 0.0, 0.0)

0

(574.0, -476.0, 1201.3)

null

133

485

196

7

2

(0.0, 0.4, 0.0, 0.9)

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

10 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

Related Questions

Loading from multiple files? 2 Answers

Saving items to a text file 1 Answer

Spawning random terrain pieces 1 Answer

Android File-io? 1 Answer

Android Multitouch 0 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