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 zeri · Jul 18, 2013 at 01:29 PM · arrayiterate

Iterate an array 4 by 4

Hi guys, i'm trying to create an iteration on a array that need to count 4 by 4. I explain better:

 var users = new Array();
     var selectDataMessage : String;
     selectDataMessage= "selectDataMessage";
         
     selectDatasMessage = URL + "?selectDataMessage="+selectDataMessage;
     var dataMessage: WWW = new WWW(selectDatasMessage); 
     yield dataMessage;
     
     users = dataMessage.text.Split(";"[0]); // this is an array

i get from php a string with all users that left a message on my game, so for example, in users, at position [0][1][2][3] i've all the information i need for a single player (name surname, gender, username)

the problem is the iteration i did something like this:

     for(var i : int = 0; i < users.length;i++){
             //Debug.Log("User length "+users.length);
             firstNames.Push(users[i]);
             lastNames.Push(users[++i]);
             userNames.Push(users[++i]);
             gender.Push(users[++i]);
     }

this one get every single position and it put them inside 4 arrays each for every single data i need.

I know it's not really good but it's the only way i found . It doesn't work anyway, it goes off by one. and return this error:

 ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
 Parameter name: index
 1

someone know how to solve this? thanks a lot.

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 hatuf · Jul 18, 2013 at 01:41 PM 0
Share

Have you used JSON before? You could send a JSON encoded array from PHP and then have the JSON parser in C# turn it into the array without any manual labor.

avatar image zeri · Jul 18, 2013 at 01:50 PM 0
Share

i tried to return a json using echo jsonencode(); but then it comes inside a string (www.text) and i don't know how to conver it to an array by using JS. I don't know anything about c#

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BiG · Jul 18, 2013 at 01:41 PM

The way you are accessing the array is a bit "dirty", as you said (it is not a good programming style to increment the cycle index directly into the iteration's body), but it seems fine (only if the array's length is a multiple of 4, obviously).

By the way,

 i >= users.length

is wrong! It should be:

 i < users.length

It's the real cause of the error.

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 zeri · Jul 18, 2013 at 01:44 PM 0
Share

ye sorry i pasted a test code in real is < . I didn't understand if users = data$$anonymous$$essage.text.Split(";"[0]); put at[0] the ; char and the real array start from [1] anyway it gives the same error.

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

17 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

Related Questions

[c#] Create visible appearence of a grid using texture or models 1 Answer

Why is iterating an array and destroying objects considered bad practice? 2 Answers

Loop Through Entire Array - Simon Game 1 Answer

Getting information from an array 1 Answer

Ways to optimize this code? iterate through inventory 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