Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(x?y:z).id causes an error when compiling to GM-HTML5 #22

Open
ze0nni opened this issue Dec 8, 2023 · 3 comments
Open

(x?y:z).id causes an error when compiling to GM-HTML5 #22

ze0nni opened this issue Dec 8, 2023 · 3 comments

Comments

@ze0nni
Copy link

ze0nni commented Dec 8, 2023

When I build this

var _items = [ { id: 42}, { id: 9001} ];
var _id = (Mathf.random(10) == 0 ? _items[0] : _items[1]).id;
Lib.trace(_id);

I will get this:

var __items_0 = { id: 42 }
var __items_1 = { id: 9001 }
show_debug_message(((random(10) == 0 ? __items_0 : __items_1)).id);

This work for windows targetes but will crash application for html5.

If enable feather inspections I have notification about this

image

@YellowAfterlife
Copy link
Member

YellowAfterlife commented Dec 8, 2023

Because of extra parenthesis..?

If so, probably file a GameMaker bug since that's a pretty basic thing that shouldn't be illegal

@ze0nni
Copy link
Author

ze0nni commented Dec 8, 2023

No, parentheses are ok

As I understand instead of this:

var _id = (cond ? item1 : item2).id

must be it:

var _item = (cond ? item1 : item2)
var _id = _item.id

I agree that this seems like a bug in gamemaker. I was confused that Feather mark this as error. I Will report for gamemaker developers.

@YellowAfterlife YellowAfterlife changed the title Bad code when use ternary operator (x?y:z).id causes an error when compiling to GM-HTML5 Dec 8, 2023
@ze0nni
Copy link
Author

ze0nni commented Dec 8, 2023

YoYoGames/GameMaker-Bugs#2426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants