Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics


A high-end code editor for all things GameMaker · By YellowAfterlife

#import magic when using instance variables

A topic by Galbenshire created Nov 17, 2022 Views: 176 Replies: 1
Viewing posts 1 to 2

I'm not quite understanding the #import feature when using it on instance variables.
As an example, here's using #import for the array functions in the Create Event of an object. Using both an instance variable & a local variable.

Inside GMEdit, it looks like this:

#event create
#import array.* as Array

// Local Variable
var _testArr:Array = new Array(6, "Sample Text");
_testArr.push("Another Text");

// Instance Variable
exampleArray = new Array(6, "Sample Text"); /// @is {Array}
exampleArray.push("Another Text");

While in the .gml file, it looks like this:

//!#import array.* as Array

// Local Variable
var _testArr/*:Array*/ = array_create(6, "Sample Text");
array_push(_testArr, "Another Text");

// Instance Variable
exampleArray = array_create(6, "Sample Text"); /// @is {Array}
exampleArray.push("Another Text");

As you can see, it appears to be working correctly for the local variable, but not the instance variable.
I'm not sure if this is a bug with the feature or an error in writing on my end, hence why I made this post.


It doesn’t work for non-local variables, as simple as that - locals are fairly “pure” in the sense that they are specific to a function (although even is now not-so-simple with 2.3 function literals), but instance variables can be accessed in a variety of ways, which slowly moves this further away from being a simple string replacement and toward being a source-to-source compiler (but I’ve already done a source-to-source compiler, I don’t want to maintain two of them).