Skip to main content
Participating Frequently
November 2, 2007
Question

Convert number to letter

  • November 2, 2007
  • 5 replies
  • 1132 views
Hi there

I am trying to find a way to convert a number to a character for a game I am working on. Currently the users score can be sent to a friend via a query string e.g. www.mygame.com/game?usersscore=111.11

This is not ideal as all the user needs to do is alter the query string to automaitcally change their score. So what I want to do is disguise the score as a series of random letters. e.g. 123.12 = abc.ab

Then when the flash reads in the query string abc.ab it converts it back to the score of 123.12

I have looked at converting the score to hexidecimal to disguise it but can you convert a decimal number with a point in it e.g.22.5 or would it only except whole numbers?

Any help on this would be much appreciated

Trevor
This topic has been closed for replies.

5 replies

Participating Frequently
November 2, 2007
yeah thats kind of the route I have just started. Basically I am taking my final score with decimal point e.g. 12.12 then multiplying it by 100 to get 1212. Then I am going to convert this number to hexidecimal to disguise the score.

One question though. How do you convert a string to a number? At the moment my conversion isn't working as the score is being turned to a string.
Inspiring
November 2, 2007
I believe what you are looking for is the Number function:

Number()

so if your variable was "score" you would convert it to a number by using Number(score) ...

btw this is AS 2.0 code, hope this helps
Participating Frequently
November 2, 2007
Thats great thanks

I have now got it converting a decimal number to hexidecimal by using the code finalscore= score.toString(16);

The final thing I need to do is work out how to convert the hexdecimal back to decimal. Any ideas????


quote:

Originally posted by: fermp
I believe what you are looking for is the Number function:

Number()

so if your variable was "score" you would convert it to a number by using Number(score) ...

btw this is AS 2.0 code, hope this helps


clbeech
Inspiring
November 2, 2007
OK well you could make a simple 'encoder/decoder' by breaking the Number string into pieces, itereate through the characters and assign a letter value for 0-9 using a switch statement to generate a new String, then reverse the process to 'read' it, from the URL variables being passed in.
clbeech
Inspiring
November 2, 2007
but if you activate this generated URL, it will only navigate in the browser that makes the call, it's not 'sending' it anywhere (like to a friend). Are you then having the user 'copy and paste' this into an email or somthing?

You could still use a Hash to encode/decode the number.
Participating Frequently
November 2, 2007
I am trying to create something very much like this games challenge a friend
http://www.totebo.com/monkey-kick-off.php

it takes the score and encodes it to letters to confuse the user
clbeech
Inspiring
November 2, 2007
how is this working? are you using a server-side php to send an email? If so you could use the LoadVars class to send the variable in the background without the query string in the URL.

Another method would be to use a 'Hash' like crc32 or md5.
Participating Frequently
November 2, 2007
I don't have the game using any serverside code.

Basically the game works by automatically generating a url when the user click on the challenge a friend button. This url is made up of 3 things. the game url (www.game.com/game?), the users name (username=Trevor) and the users score (users score = 12.12)

So the outputted query string is www.game.com/game?username=Trevor&score = 12.12

So i need to somehow encode the score to make it not so identifyable.