This is a very common error for beginner, which I would just like to explain.
There are two types of values: string values and real values, the later of them may only contain digits. For real values you can do all sorts of math; but to strings, although they happen to be digits you can’t. Game Maker will always treat strings as a bunch of characters, which meaning it cannot understand. Thus you will only be able to apply simple comparisons to strings, like if it is equal. You cannot say “if a > b” as long as a and b are strings containing numbers, but if they are real values containing numbers then you may do so. Because Game Maker will “understand” the real values…
<b>This is what causes the problem :</b> usually what causes the error “Cannot compare arguments” is that you combine string values and real values. You may for an example write “if a > b”, because a is a real containing the value five and b is a string that contains the number 3, but you didn’t realize it was a string. That is what causes the error.
<b>To solve the error</b> you must “translate” the values and there are two functions for this: string() and real(). So this would work: “if real(a) > real(b)”.
Important to understand is that variables are classified not only once as either string or real. Whether they are string values or real values depends on what functions you pass onto them and how they are initialized. The variables have no “memory”, they are what they was last set to be.
.
Users logged in:
Comments
Loading comments...