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
1
Question by tertle · Jan 28, 2011 at 12:34 PM · networkingwww

yield return WWW; not returning

Been trying to implement a highscore system, and I was just testing/starting out with the standard highscore found in the wiki.

http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores

Been having issues though, it wouldn't add scores to the database. Using identical php scripts from the wiki except for own values and rewrote the javascript to c#.

IEnumerable PostScore(string username, int score) { var hash = Md5Sum(username + score + _secretKey); var highscoreUrl = _addScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + score + "&hash=" + hash;

 var hsPost = new WWW(highscoreUrl);
 yield return hsPost; // Wait until the download is done
 if(hsPost.error != null)
 {
     print("There was an error posting the high score: " + hsPost.error);
 }

}

Never worked. I checked to make sure md5 matched, i printed off the url and manually used it and it all worked fine, but when that script runs it never added a score to the database.

I finally decided to test it without the yield

void PostScore(string username, int score) { var hash = Md5Sum(username + score + _secretKey); var highscoreUrl = _addScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + score + "&hash=" + hash;

 var hsPost = new WWW(highscoreUrl);

}

Works fine, adds the score to the database but I'd obviously like the added functionality and options of using the yield so could anyone explain to me why it's not working?

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
3
Best Answer

Answer by Mike 3 · Jan 28, 2011 at 12:41 PM

Make sure you're calling the function with StartCoroutine(PostScore(username, score));

If you leave that off, you'll end up with it just not doing anything in that function

If that's not it, i would suggest a slightly different yield:

while (!hsPost.isDone && hsPost.error == null)
{
    yield return null;
}

That should pause until the download is complete or you get an error

Comment
Add comment · Show 2 · 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 tertle · Jan 28, 2011 at 12:44 PM 0
Share

thank you, thank you, thank you! I knew I forgot something simple (StartCoroutine).

avatar image Bunny83 · Jan 28, 2011 at 01:13 PM 1
Share

Yeah, in C# you have to explicit start a coroutine and that's why i prefer C#. It's clearer what happens. Strict typing also just helps to avoid logical errors. In JS everything seems to be defined a bit blurry.

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

1 Person is following this question.

avatar image

Related Questions

unity c# RPC 0 Answers

opening a webpage? 1 Answer

using Application.OpenURL for opening new tab? 2 Answers

how to test your multiplayer game 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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