You are not logged in.
Pages: 1
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
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.
Offline
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
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
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
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
Pages: 1