Script function not defined before object create event

Zephni

Member
Hi all. The documentation and looking up on the forums suggest that if using the new style functions and structs etc within scripts they should be available before the create method of an object., but I am finding after many tests the scripts are always too late to the party. To re-create, make a script with this:

GML:
Vector2 = function(_x, _y) constructor
{
    x = _x;
    y = _y;
}
And then make an object with a create event that has:

Code:
someVar = new Vector2(3, 5);
I always get an error saying that Vector2 is undefined at this point, but I assume this must not be correct game maker functionality because of course you would always want your global functions etc defined before your objects are created. Is there something I'm missing here to make sure scripts are read within the correct execution order?

Thanks in advance!
 

FrostyCat

Redemption Seeker
If you want it to be global, then declare it in a script using the named function syntax, not in an event using the anonymous function syntax.
GML:
function Vector2(_x, _y) constructor
{
    x = _x;
    y = _y;
}
 
Top