x


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?

more ▼

asked Apr 13 '10 at 04:36 PM

TinyUtopia gravatar image

TinyUtopia
270 22 26 38

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

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.

more ▼

answered Apr 13 '10 at 05:50 PM

Michael La Voie gravatar image

Michael La Voie
2.3k 7 12 43

Yes, Michael. That was it. My variables were floats and it needed strings. Thanks a lot!

Apr 13 '10 at 06:29 PM TinyUtopia

Not a problem. I fit helped you, please vote it up and mark it as accepted.

Apr 13 '10 at 06:46 PM Michael La Voie
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x426
x44
x38

asked: Apr 13 '10 at 04:36 PM

Seen: 839 times

Last Updated: Apr 13 '10 at 04:36 PM