- Home /
Error on HSController.js
I've gotten the server side highscores script from the Unity Wiki and I'm getting an error when I run it in my game.
here is the error I receive:
InvalidCastException: Cannot cast from source type to destination type.
HSController+postScore$12+$.MoveNext () (at Assets\Scripts\HSController.js:15)
And here is the line that the error refers to:
var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
It appears that the script is working to load the existing highscores from the database, so it's just something in Unity. Maybe I have to run a build of the game to get the php request working?
Answer by Michael La Voie · Apr 13, 2010 at 05:50 PM
This is a type conversion error. It looks like you're building a string by adding together string literals and some variables. My best guess is that one of the variables is not a string type and cannot be converted automatically. Without seeing the whole file, I don't have enough context, but that doesn't really matter.
A simple way to debug that line is to split it up and see where the problem occurs:
var highscore_url = addScoreUrl + "name=";
var escapedUrl = WWW.EscapeURL(name);
highscore_url += escapedUrl;
highscore_url += "&score=" + score;
highscore_url += "&hash=" + hash;
Please run this code in its place and see what line the error occurs on. That will reveal which variable is the problem.
Yes, $$anonymous$$ichael. That was it. $$anonymous$$y variables were floats and it needed strings. Thanks a lot!
Not a problem. I fit helped you, please vote it up and mark it as accepted.
$$anonymous$$icheal Can You Answer $$anonymous$$ine Please ? http://answers.unity3d.com/questions/620073/reciving-data-from-server.html
Your answer
Follow this Question
Related Questions
postScore Server Side Highscores tutorial 1 Answer
Help with Server Side HighScores 1 Answer
MD5 Implementation - Server Side High Score Problems 1 Answer
Unity networking tutorial? 6 Answers