GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: GML Reference » Undocumented string features » 2007-12-16 00:36:03

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?

#2 Re: GML Reference » Undocumented string features » 2007-12-11 18:27:42

laugh 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:

Expanda = "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:

Expanda = "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.

#3 Re: Script Submission » ROT13 Encryption » 2007-11-08 07:23:53

You guys are so picky. tongue Fixed script:
EDIT: It seems that I can't add the extra indent to the code...

Expand/*
**  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;
}

#4 Re: Script Submission » ROT13 Encryption » 2007-11-07 17:27:11

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 tongue) and the string_length() in the loop. Here is the new script:

Expand/*
**  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;
}

#5 Re: Script Submission » ROT13 Encryption » 2007-11-05 18:48:54

I added the "i" variable to the declaration line and changed "text" to "str."

#6 Script Submission » ROT13 Encryption » 2007-11-04 17:53:25

Austin
Replies: 14

Here is the script I made as a request at the GMC, it will encrypt/decrypt text into/out of ROT13 format:

Expand/*
**  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... ^^;

Board footer

Powered by FluxBB