• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 HTML bug work around. Any ideas?

Roldy

Member
Already submitted a bug to YoYo; however, normally I can find work arounds for most bugs in HTML export, I can't come up with a work around for this.

Here is the bug. A function that calls 'draw_tile' will not draw anything if it is called from a function using member operator (dot operator) off a struct.

Example:

GML:
//------------------------------------------
// Some Script file

function SomeStruct() constructor {
    static draw = FunctionThatDrawsATile;
}

function FunctionThatDrawsATile(_xOffset) {
    draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
}
GML:
//------------------------------------------
// Some Objects Create event
myStruct = new SomeStruct();

//------------------------------------------
// Some objects Draw Event

// This will draw
draw_tile(ts_some_tileset, 1, 0, 10, 10);

// This will draw
FunctionThatDrawsATile(50);

// This will not draw
myStruct.draw(100);
I have a bit a tile drawing wrapped up in structs and when I went to test on HTML none of it works. :(

I could re-write it for now to not use structs or wait for HTML bug fix, but would like to find a work around. Usually I can deduce what the underlying problem is and work around it, but this one has me stumped. I've tried making it a method instead of a simple function reference but that didn't work. All other drawing (draw_sprite, draw_circle, instance draw_self) works fine, just not draw_tile.

Any ideas? Maybe I am just tired and not seeing it.


EDIT: Maybe to make it even clearer draw_tile will not work inside a 'with' block when passed a struct. e.g.
GML:
with (someStructInstance) {
    // This will not draw on HTML5 export
    draw_tile(ts_some_tileset, 1, 0, 10, 10);
}
 
Last edited:

FrostyCat

Redemption Seeker
It isn't working properly because you are giving the constructor an unbound script function reference, as opposed to a bound method.

Here is an example that I got working on HTML5 (Runtime 2.3.2.426):
GML:
function SomeStruct() constructor {
    static draw = method(self, FunctionThatDrawsATile);
}

function FunctionThatDrawsATile(_xOffset) {
    draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
}
And another:
GML:
function SomeStruct() constructor {
    static draw = function(xx) {
        FunctionThatDrawsATile(xx);
    };
}

function FunctionThatDrawsATile(_xOffset) {
    draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
}
 

Roldy

Member
It isn't working properly because you are giving the constructor an unbound script function reference, as opposed to a bound method.

Here is an example that I got working on HTML5 (Runtime 2.3.2.426):
GML:
function SomeStruct() constructor {
    static draw = method(self, FunctionThatDrawsATile);
}

function FunctionThatDrawsATile(_xOffset) {
    draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
}
And another:
GML:
function SomeStruct() constructor {
    static draw = function(xx) {
        FunctionThatDrawsATile(xx);
    };
}

function FunctionThatDrawsATile(_xOffset) {
    draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
}

#1 Your solution does not work, at least not in Chrome/Edge. If you read the OP I stated I had already tried it.

#2 Your solution SHOULD NOT work, at least in this context, scope is irrelevant. There should be no difference between these three:

GML:
var draw = FunctionThatDrawsATile


// All three of these are doing the same thing (at least should be)
// Taking an integer (script asset) and calling it as a function

draw(10);                    // Invoking a function reference from this scope

FunctionThatDrawsATile(10);  // Invoking a function reference from this scope

myStruct.draw(10);     // Invoking a function reference from struct scope
                     // However, there is no scope specific code within the function
                    // If we make it a method of struct the scope does change to struct scope no matter where it is called from
                   // however, that does not solve the issue. (continues not to draw).

Regardless making it a method does not solve it on my end. What browser are you using?

Furthermore, bound or unbound, it works in Windows either way. This is a HTML5 bug presenting drastically different behavior between platform.

EDIT: Tested in Edge browser.. Same behaviour.
 
Last edited:

Roldy

Member
@FrostyCat I would be curious to know your setup: Browser and OS version as I will append that info to bug report.

As well, if a method works for you in your browser, did you happen to test the original unbound function call as well. I am guessing that it works for you and you are unable to reproduce the original bug posted in OP. The scope should have no effect as we are only calling global named functions (draw_tile and FunctionThatDrawsATile) with no reference to any other scope other than function local.
 

Roldy

Member
The closest thing I can come up with to a work around for this is to use some object instance to draw tiles for HTML. e.g.

GML:
function SomeStruct() constructor {
    static draw = FunctionThatDrawsATile;
}

function FunctionThatDrawsATile(_xOffset) {
    if (os_browser != browser_not_a_browser) {
        with (obj_some_singleton_object) {
            draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
        }
    } else {
            draw_tile(ts_some_tileset, 1, 0, 10 + _xOffset, 10);
    }
}
Pretty crappy, but like I said the only draw function that doesn't work is draw_tile (that I know of). For whatever reason, draw_tile does not function when called from within the context of a struct.
 
Last edited:
Top