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 Kiloblargh · Mar 06, 2013 at 10:02 AM · webplayerfacebookstringsendmessagesplit

Trying to parse Facebook FQL response with String.Split in webplayer; no luck

I finally worked out how to do it on the html side of things, I am successfully getting the entire response.data into a String ( which I have verified with console.log ) and sending it to the Unity webplayer. But then I am failing to decode it in Unity, which should have been the easy part.

I can't figure out what I'm doing wrong here.

 function ParseFQLResponse (inString : String)
 {
 var chopChar : char[] = new char[1];
 chopChar[0] = ";"[0];
 var diceChar : char[] = new char[1];
 diceChar[0] = ","[0];
 
 var chop : String[] = inString.Split(chopChar);
 for (var p : int = 0; p < chop.Length; p++)
     {
     var dice : String[] = chop[p].Split(diceChar);
     if (dice.Length == 4)
         {
         fbFriendIDs.Add(dice[0]);
         fbFriendNames.Add(dice[1]);
         fbFriendsOnline.Add(dice[2]);
         fbFriendsWithGame.Add(dice[3]);
         }
     else
         {
         playerText.text = "oops "+dice.Length;
         }    
     }
 playerText.text = fbFriendIDs.Count+","+fbFriendNames.Count+","+fbFriendsOnline.Count+","+fbFriendsWithGame.Count+"  "+fbFriendIDs[0]+" "+fbFriendNames[0]+" "+fbFriendsOnline[0]+" "+fbFriendsWithGame[0];
 ProcessFBFriendList();    
 }

This gives me the message "oops 1". The second message never appears.

This is the Javascript function on the webpage where the player is embedded:

 function OnUnityReady()
     {
     GetUnity().SendMessage("_MasterControl","PersonalizeFBData",gPlayerFBID);
     var outString = "";
     FB.api('fql', {q : 'SELECT uid, first_name, online_presence, is_app_user FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me())'}, function(response) {
         console.log(response.data.length);
         for (var i = 0; i < response.data.length; i++)
             {
             outString += (response.data[i].uid + "," + response.data[i].first_name + "," + response.data[i].online_presence + "," + response.data[i].is_app_user + ";");
             }
         console.log(outString);
         });
     GetUnity().SendMessage("_MasterControl","ParseFQLResponse",outString);    
     }


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 Graham-Dunnett · Mar 06, 2013 at 12:48 PM

This is a classic example of why doing some testing is so critical. You're trying to do a facebook thing, I know, but in reality, all that ParseFQLResponse() does it break up a string that you send it. So, make up some simple tests:

 ParseFQLResponse("");
 ParseFQLResponse("a,b,c,d;");
 ParseFQLResponse("a,b,c,d;1,2,3,4;");

Obviously you'll want to comment out the call into ProcessFBFriendList(). Do this from Unity, and add debugging code to your function to see what actually happens. My suspicion is that the Split("fred;", ";") will give you two results, fred and an empty string, where you expect to get just a single value back.

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 Kiloblargh · Mar 06, 2013 at 06:38 PM 0
Share

Your suspicion was right- and I made a function to write to the JavaScript console with an external call, since I was testing online and couldn't do Debug.Log. The onscreen text$$anonymous$$esh was a poor substitute because the last thing sent replaces all the rest, and the "oops 0" made me think it wasn't working for any of them.

What I had to do was modify the web script so it output something like ";,a1,b1,c1,d1;,a2,b2,c2,d2;,a1,b1,c1,d1" so that the empty string is now at the start, and then check for 5 values ins$$anonymous$$d of 4 and start the for loop at [1] ins$$anonymous$$d of [0] to skip over it.

Which made me feel like String.Split is stupid, but after reading a post on StackOverflow by someone who felt the same way and dozens of replies by people with far thicker neckbeards and richer monitor tans than my own explaining at great length why you really DO want it to return an empty string... I will just have to take their word for it and downgrade my opinion to "String.Split is unintuitive."

The one other problem which took me longer to figure out was that I was sending the string after the FB.api callback ins$$anonymous$$d of inside it, which meant it actually happened before, so the string was still empty. Now it finally works fine.

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

11 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

Related Questions

Problem with UnityObject2.SendMessage | communicating with the web player 0 Answers

GetUnity() on webplayer not working properly 1 Answer

"Array index is out of range" Please Help !!! 2 Answers

Splitting String only on a "space". Using my method --- FIXED 2 Answers

SendMessage() with ActiveX only works once? 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