GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2007-12-11 14:51:07

Yourself
Member
Registered: 2007-10-09
Posts: 48

Undocumented string features

There's a few things about strings that everyone should know but are undocumented.

One is string comparison.  The comparison operators all work with strings just fine.  This seems to be pretty common knowledge, but isn't explicitly documented anywhere.

Second you can actually multiply strings and integers:

"a"*5

This is a valid GML statement and produces the string "aaaaa" (does the same thing as string_repeat but with less typing).

Offline

#2 2007-12-11 18:27:42

Austin
Member
From: Florida
Registered: 2007-10-17
Posts: 9

Re: Undocumented string features

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.

Offline

#3 2007-12-11 19:00:47

Yourself
Member
Registered: 2007-10-09
Posts: 48

Re: Undocumented string features

I can't confirm that.  I'm glad that's not the case.  Those operators (when used in an expression) should mean the same thing.

Offline

#4 2007-12-12 03:45:15

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Undocumented string features

Interesting, 5*"a" does seem to work like string_repeat, but "a"*5 does not. The number has to precede the operator otherwise it throws an error in GM5/6/7.

Sorry, Austin, using GM5/6/7 I can not confirm any difference between = and == in your example.


Abusing forum power since 1986.

Offline

#5 2007-12-16 00:36:03

Austin
Member
From: Florida
Registered: 2007-10-17
Posts: 9

Re: Undocumented string features

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?

Offline

#6 2007-12-17 11:52:16

Quimp
Member
Registered: 2007-10-09
Posts: 15

Re: Undocumented string features

If it's an online game, perhaps it happened in a PHP file (for example), where if (a = b) checks if setting a to b worked (true).

Offline

Board footer

Powered by FluxBB