Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert number to letter

New Here ,
Nov 02, 2007 Nov 02, 2007
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
TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 02, 2007 Nov 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2007 Nov 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2007 Nov 02, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 02, 2007 Nov 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 02, 2007 Nov 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2007 Nov 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 02, 2007 Nov 02, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2007 Nov 02, 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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 02, 2007 Nov 02, 2007
:
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2007 Nov 02, 2007
LATEST
quote:

Originally posted by: clbeech
:


That code works great on its own but when I try and put it in my game it doesn't seem to work properly. Basically my send to a friend section appears on the last frame of the game. At this point i give the user the url using the encode function.
I have added your code and have got the game encoding the the score to the letters (Great so far)

However if you are starting a game the decode function needs to be on the first frame of the flash movie to show the user their friends score (e.g. so it can work out that bbcc is 1122 for example) based on the query string. However the decode function is never passed the encode result as the flash movie doesn't get to the last frame:

decode(coded); //send to decode the test string

So I need to be able to encode on the last frame (which is done) and then decode on the first frame.

I tried this but its not outputting anything:


varchallengerscore = "ab"; //I am trying to pass the value of this variable to the decode function
decode(varchallengerscore)

function decode(str) {
var decoded:String='';
for(var i=0; i<str.length; i++) {
if(i==str.length-2) {
decoded+='.';
}
for(var j=0; j<char.length; j++) {
if(char==str.charAt(i)) {
decoded+=j;
break;
}
}
}
trace(decoded); //test output
}



any ideas? Also I hope this all makes sense to you and I am describing the situation ok. So far you guys have been a massive help so thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines