Integer access


Jump to: navigation, search

In GML, everything's an integer, because GML is for novices.

Accessing a variable in Game Maker is done by specifying an instance ID (or variable containing the ID) and using . to fetch the member. Function int instance_nearest(int x, int y, int object) returns the integer ID of the nearest instance of object "object." A variable can be accessed in it like so:

instance_nearest(x,y,object0).x = 0;
random_integer(2).randomlySelected = true;

In ENIGMA, no hash map is used to store variables by name, so access is hard coded into functions. For efficiency, since some variables are guaranteed to exist in all instances, these "global locals" are recalled using the function enigma::glaccess(), or "global local access". It takes the integer as its parameter, and returns a pointer to the bottommost local tier which contains all global locals. The member can then be accessed from that pointer via standard C.

    enigma::glaccess(object0)->x = 0;

Other variables don't exist in all instances. They are disambiguated typewise at compile time, and an accessor is generated for each of them. The resulting code looks like this:

    enigma::varaccess_randomlySelected = true;
Personal tools