You are not logged in.
Pages: 1
How odd. You seem to be right...
But, I specifically remember coding an online game where user names were stored in INI files and I had that very problem. Maybe it is a problem with the INI files?
Great find!
One more thing that I don't think is documented is that string comparison is slightly different than number comparison. For example, if you compare two strings with the same letters (just different capital letters) with just the "=" operator, then the "if" statement will ALWAYS be true. Like so:
a = "Test";
b = "teSt";
if a = b
return true;
else
return false;
That code will ALWAYS return true.
However, if you compare two strings with the same letters (just different capital letters) with just the "==" operator, then the "if" statement will ALWAYS be false. Like so:
a = "Test";
b = "teSt";
if a == b
return true;
else
return false;
That code will ALWAYS return false.
This is useful when you want to check if a user name or password is correct/taken already.
You guys are so picky. Fixed script:
EDIT: It seems that I can't add the extra indent to the code...
/*
** Usage:
** val = rot13(text);
**
** Arguments:
** text 1st argument, text to be encrypted/decrypted
**
** Returns:
** val the encrypted/decrypted text
**
** Notes:
** Only works for letters, that means no numbers, symbols, spaces, etc.
**
** GMLscripts.com
*/
{
var a,b,str,len,val,i;
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
b = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
str = string_letters(argument0);
len = string_length(str);
val = "";
for (i=1; i<=len; i+=1)
val += string_char_at(b,string_pos(string_char_at(str,i),a));
return val;
}
I was just trying to make the code as short as possible, that is why I had the "a" and "b" variables (and I couldn't think of a better name ) and the string_length() in the loop. Here is the new script:
/*
** Usage:
** val = rot13(text);
**
** Arguments:
** text 1st argument, text to be encrypted/decrypted
**
** Returns:
** val the encrypted/decrypted text
**
** Notes:
** Only works for letters, that means no numbers, symbols, spaces, etc.
**
** GMLscripts.com
*/
{
var a,b,str,len,val,i;
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
b = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
str = string_letters(argument0);
len = string_length(str);
val = "";
for (i=1; i<=len; i+=1;)
val += string_char_at(b,string_pos(string_char_at(str,i),a));
return val;
}
I added the "i" variable to the declaration line and changed "text" to "str."
Here is the script I made as a request at the GMC, it will encrypt/decrypt text into/out of ROT13 format:
/*
** Usage:
** val = rot13(a);
**
** Arguments:
** a 1st argument, text to be encrypted/decrypted
**
** Returns:
** val the encrypted/decrypted text
**
** Notes:
** Only works for letters, that means no numbers, symbols, spaces, etc.
**
** GMLscripts.com
*/
{
var a,b,str,val,i;
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
b = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
str = string_letters(argument0);
val = "";
for (i=1; i<=string_length(str); i+=1;)
val += string_char_at(b,string_pos(string_char_at(str,i),a));
return val;
}
This probably could be optimized further, it was just a quick request... ^^;
Pages: 1