문제

It appears that in Game Maker 8, 8.1, and Studio (at least) that the assignment operator = is identical to the comparison operator ==. For example, these lines do the same thing:

if (a=b) {}
if (a==b) {}

Is this function meant to be friendly to new users? Should I continue using == or switch to =? Or does it make no difference?

P.S. Things like incrementing still work with = similarly to ==:

if a=b++{} //b is still incremented, but a does not change
도움이 되었습니까?

해결책

This functionality was left over from previous versions as stated in the GameMaker help file.

"However, this is a legacy from old GameMaker versions and you should use the == operators for comparing and = for assigning."

It would be good practice for you to use == when comparing as that is what it is designed for. Also, if you were to move onto another languages like PHP, using the = operator would actually initialize the variable in the if statement. This could give you quite a headache if you are in the habit of using the single = operator.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top