The gml_pragma function affects how the given target compiles your code and should be called with the different commands to further optimise the final compilation of your project. These commands are effectively pre-processed before the game is compiled and so the function can be placed anywhere in your project and it will still be processed before the game is fully compiled. The available commands are as follows:
gml_pragma("global", "Init()");
This will call the script function "Init" before the first room of the game is run. Note that the GML supplied as the second argument must be a compile-time constant, and also note that you cannot use this pragma to create instances or perform any operations that require a room (or anything in a room) to function.gml_pragma("optimise", "js_array_check", "push, off");
This pragma will make the compiler omit type checking code on arrays when it generates JavaScript code.gml_pragma("Texgroup.Scale", "level1", "2");
This will halve all the textures in the "level1" texture group.gml_pragma("UnityBuild", "true");
The benefit of doing a unity build is that builds are faster but the down side is that it does a full build each time so even if you change a single part of the code it will build everything again without using any cached files. This has been added specifically for the Xbox One export using the YYC although it can be called for other builds (YYC only). For more information on unity builds, please see here.NOTE The first argument to the gml_pragma function must be a compile-time string constant and not a variable.
Compiler OptimisationsCompiler Optimisations
Compiler optimisations can be provided with the "optimise" (or "optimize") pragma. Their basic syntax is:
gml_pragma("optimise", "<specific_optimisation>", "<control>");
"<specific_optimisation>" is a string containing the specific optimisation to modify.
"<control>" is a string that contains a comma-delimited list of commands that control the optimisation from this point in your code:
The following table lists all optimisations that you can use:
Optimisation | Description |
---|---|
js_array_check | If ON then the compiled code will include checks that variables are arrays and do basic error checking on the array, omitted if OFF. These checks are done at each use of the array. NOTE If OFF then you need to make sure that every variable used as an array is definitely of type array before using it. |
js_error_check | If ON then the compiled code will include checks in the generated JavaScript code to bring it in line with how the VM/YYC runner handles errors. These checks will be omitted if OFF. NOTE This can be safely omitted if your code is not erroring when used, generally something that can be disabled once your code is working error free. |
js_check_index | If ON then the generated code will include checks on the index on array access (read and write) to catch out of range errors. If OFF you need to make sure to always use an array index that's within the array's length (i.e. from 0 to array_length-1). |
js_pre_post_no_long | If ON then increment ++ and decrement -- expressions are not checked to see if they operate on values of type int64 (or Long in JavaScript). You need to make sure that no variables are of type int64 when using the ++ and -- operators. |
js_use_infix_ops | If ON then JavaScript's binary operators +, -, *, etc. are used in preference to using GameMaker's type checking functions. In this case you need to make sure that all variables used in the expression are of type real. |
As an example, to optimise the following function:
function multiples_of_two()
{
var a = [];
for (var i = 0; i < 100; i++)
{
a[i] = i * 2;
}
}
You would then add gml_pragma statements as follows:
function multiples_of_two()
{
gml_pragma( "optimise", "js_array_check", "push, off");
gml_pragma( "optimise", "js_error_check", "push, off");
gml_pragma( "optimise", "js_check_index", "push, off");
gml_pragma( "optimise", "js_pre_post_no_long", "push, on");
gml_pragma( "optimise", "js_use_infix_ops", "push, on");
var a = [];
for(var i = 0; i < 100; i++)
{
a[i] = i * 2;
}
gml_pragma( "optimise", "js_use_infix_ops", "pop" );
gml_pragma( "optimise", "js_pre_post_no_long", "pop" );
gml_pragma( "optimise", "js_check_index", "pop" );
gml_pragma( "optimise", "js_error_check", "pop" );
gml_pragma( "optimise", "js_array_check", "pop" );
}
gml_pragma(command, [optional...]);
Argument | Type | Description |
---|---|---|
command | String | A string with one of the commands listed above. |
[optional] | String | Some of the available commands require an optional argument or arguments. These are explained above for each command. |
N/A
gml_pragma("forceinline");
The above example code will force the script function where it is used to be in-lined on compile.