UnderminersTeam / UndertaleModTool

The most complete tool for modding, decompiling and unpacking Undertale (and other GameMaker games!)
GNU General Public License v3.0
1.19k stars 233 forks source link

Add parentheses to nested comparison expressions #1813

Closed Jacky720 closed 5 months ago

Jacky720 commented 5 months ago

Description

Minor fix for a bug reported on Discord where the code x -= ((1 + statetime) < (2 + statetime)) < 4 would decompile as x -= (1 + statetime) < (2 + statetime) < 4.

Caveats

Only the possible exceptions where parentheses might be helpful to other, yet rarer, expressions, which would have already been decompiling incorrectly.

Notes

N/A

github-actions[bot] commented 5 months ago

Download the artifacts for this pull request here:

GUI:

CLI:

CST1229 commented 5 months ago

a < b < c is valid GML syntax (it's accepted by GameMaker's compiler), so I think it might be better/saves parentheses to instead allow multiple comparison operators next to eachother in the compiler (like it already is possible with math), which I already did for UTMTCE. Maybe I should PR that.

Jacky720 commented 5 months ago

What does GameMaker's compiler produce in this case? If it's like Python, it would be a < b && b < c, but if it's actually producing (a < b) < c as in turning the first comparison from boolean to number, we should decompile that.

Jacky720 commented 5 months ago

Yeah, I just spun up a dummy project, that's exactly what it's doing. image "a < b" is false, 0, and 0 < c. (a < b) < c is the opposite of the code's intent, of course, but consistent with the new decompilation (and the mod tool compiler can handle it).

Miepee commented 5 months ago

Even though it is a compiler bug, let's just always force parattheses for now on. Makes that code way more readable and prevents user bugs.