Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[SOLVED] nested ternary operators violating GM conventions

A topic by bowsette_game created Apr 15, 2019 Views: 490 Replies: 4
Viewing posts 1 to 2
(1 edit)

I'm trying to compile a project using the following command:

haxe -debug -lib sfhx -lib sfgml -cp src -js ../extensions/Haxe.extension.gmx._ -main Class -dce full -D sfgml-assets-path=../my_project.project.gmx -D sfgml_snake_case -D sf_pretty -D sfgml_local=_

It compiles successfully from Haxe, but the generated code uses ternary operators, which is throwing errors when compiling the GMS1 project. I double checked the build.hxml file and sfgml_next isn't present.

However, if I target a .gml file, the compiler replaces ternary operators with the if;else equivalent code, and it works fine. I've also noticed that targeting the gmx._ file seems to get rid of auxiliary local variables and substitutes them for their values.

Developer

What GMS1 version are you using? Ternary operators are supported in extensions from 1.4.1763 and onwards.

If you need to target an ancient version, define sfgml_version=1.4.1700 or whatever

(4 edits)

I'm using 1.4.9999.

This is the error:

Error : got '?' expected ')'

Edit: putting a few more bracers in the generated code solved it. Essentially, there is a statement with multiple ternary operators, and I changed them like that:

(a) ? b : c --> ((a) ? b : c)

And it worked perfectly afterwards. Any idea on why it doesn't work out of the box?

Developer

Pushed a fix for that on git.

Wow, thought this was complicated and wasn't expecting a fix that fast. Many thanks!