YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
26 stars 8 forks source link

Invalid comparision state (stringified number with text is equal to real number) #6396

Closed tabularelf closed 5 months ago

tabularelf commented 5 months ago

Description

There seems to be an oddity where having "-1 Hello world" == -1 will equal to true, even though one is clearly a string and not a number.

Steps To Reproduce

  1. Boot up project.
  2. Run game.
  3. See debug messages & Script1 for comparision results. (You can find it under ===DEBUG START===, game will autoclose)

Which version of GameMaker are you reporting this issue for?

IDE v2024.600.0.579 Runtime v2024.600.0.605

Which operating system(s) are you seeing the problem on?

Windows 10.0.19045.0

5ef32c1f-33e8-4482-87be-4c820a8e34d8

tabularelf commented 5 months ago

Here's the code I used for the sample project provided, if you'd like to see it directly.

show_debug_message("-1 Hello world" == -1);
show_debug_message("0 Hello world" == 0);
show_debug_message("1 Hello world" == 0);
var _str = "1 Hello world";
show_debug_message(_str == 0);
show_debug_message(_str == 1);
DragoniteSpam commented 5 months ago

this is apparently working as designed but i really wish it wasn't because it makes debugging a pain in the ass image

tabularelf commented 5 months ago

If we can't real("100000 Hello world") into a real, then this shouldn't be true either.

DragoniteSpam commented 5 months ago

In general I don't like permission interpretations of == comparisons. The number of times when you actually want it to work like that is dwarfed by the number of times when you do it by accident and spent 6 hours debugging.

stuckie commented 5 months ago

This is by design due to legacy support - it'll find the first number and use that.

YellowAfterlife commented 5 months ago

This is by design due to legacy support - it'll find the first number and use that.

Can the definition of "legacy support" be elaborated here? From testing:

Was this part of the GMS 2.2.5 update with much-loved (not really loved) "23" - 1 ➜ 22?

tabularelf commented 5 months ago

Could really use some further clarification, yeah. What "legacy" support?

rwkay commented 5 months ago

It has been this way since 2.3 - others have built code that work using this... 2.3 is legacy now...

YellowAfterlife commented 5 months ago

It has been this way since 2.3 - others have built code that work using this... 2.3 is legacy now...

Could it be a checkbox as it's been with "copy on write"? Neither this or "4" - 1 are documented in the manual at all, so I don't think anyone relied on this except on accident (which is arguably a good reason to remove the behaviour).

DragoniteSpam commented 5 months ago

if i had to choose between not having to real() my inputs explicitly and spending hours tracking down bugs involving strings being treated as numbers erroneously, i think i'd rather choose having to real() my inputs explicitly

if changing it breaks any projects, it'll take like five minutes to track down the offending lines and real()ing them explicitly