GMWolf
aka fel666
GMStruct
Struct generation for GameMaker Studio
Early alpha build
download on itch.ioStruct generation for GameMaker Studio
Early alpha build
Source on GitHub
Blog post 1: GMStruct - extending GML with code generators
Blog post 2: GMStruct Inheritance and Types
I need testers!
The project is still in very early development, and there is sure to be a lot of bugs present!
If you make use of this in a project, or tinker around with it, Please leave feedback both on stability and features! Thanks!
What is a Structure?
Simply put, a structure is a collection of named values (called attributes), under a single name.
An example would be wanting to store information on a car. You would want to store a model, colour, age.
Structures allow you to bundle these named values into a single variable, from which you could later retrieve the age, colour, etc.
An example would be wanting to store information on a car. You would want to store a model, colour, age.
Structures allow you to bundle these named values into a single variable, from which you could later retrieve the age, colour, etc.
What is GMStruct?
GMStruct is a language and a tool to introduce Structures to GameMaker studio 2.
The language (gms) allows you to define structures and their attributes in a clear and practical manner.
The tool translates that definition language into usable GML code.
The language (gms) allows you to define structures and their attributes in a clear and practical manner.
The tool translates that definition language into usable GML code.
How does it work?
The GMS language is fairly simple and quick to learn. After writing you GMS in your editor of choice, The tool can be used to generate the GML into any directory. This will generate a number of gml files, ready to be draged into your projects scripts folder.
These will include scripts to instanciate structures, Get and Set values, as well as checking structure types.
These will include scripts to instanciate structures, Get and Set values, as well as checking structure types.
The GMS languages.
The basic syntax for a structure is a folows:
Code:
structure foo {
name,
age
}
A structure can inherit attributes from another. This means that it will have all the same attributes as its parent structure, as well as the one it defines.
This is done with the following syntax:
Code:
structure bar : foo {
colour
}
This structure will therefore have the attributes name, age and colour.
The type of the bar structure will also be of both type foo, and bar, allowing you to call 'foo' functions on a bar structure.
You can set default values for attributes, removing the need to initialise them when instantiating the structure:
Code:
structure tile {
xPos,
yPos,
colour = c_green
}
The generated code is also very straight forward to use. For every structure, there will be a instantiation script, and a single script for each of its attribute to get or set its value.
The generated scripts will also include functions to get the type of a given attribute, or test the type of a structure.
consider the following source:
The generated code would be able to be used in the following manner:
Note, is_a is not a simply checking if the types matches, as it will take inheritance into account as well.
What's Next?The generated scripts will also include functions to get the type of a given attribute, or test the type of a structure.
consider the following source:
Code:
structure foo {
size,
age
}
structure bar : foo {
colour
}
Code:
var a_foo = new_foo(42, 3);
//This creates a new foo structure, with size 42 and age 3. it is assigned to the variable a_foo
var size = foo_size(a_foo);
//This retrieves the size attribute of the foo structure stored in the variable a_foo.
foo_size(a_foo, 12);
//This sets the the size attribute of a_foo to 12. Notice that the setter script isthe same as the getter, but with one more argument.
var b = new_bar(12, 3, c_green);
//this create a new bar structure with size 12, age 3 and colour c_green.
var size = bar_size(b);
var size2 = foo_size(b);
//The above are two equally valid ways of retrieving the size of a bar structure, as a bar structure is also a foo structure.
if is_foo(b) {
//do something
}
//This will check if the structure in b is of type foo. This will return true as b is of type bar, which is also foo.
var t = get_type(a_foo);
//The above will find the type of structure a_foo (which is foo).
if is_a(b, structs.foo) {
//do something
}
//Another way of checking type. The output of get_type can be used as the type to check against.
There is still a lot that can be done. Introducing name spaces, functions and so on to make GMStruct as versatile as possible. THe ultimate goal is to be able to develop intire subsystems in GMStruct to be seamlessly imported in GMStudio 2.
For this, I will need the help of the community. Helping with testing at first, but eventually introducing new features, UI, plugins and so on.
This is why i have made the project source open to anyone on github (link above), so that anyone can experiment with the system.
For this, I will need the help of the community. Helping with testing at first, but eventually introducing new features, UI, plugins and so on.
This is why i have made the project source open to anyone on github (link above), so that anyone can experiment with the system.
Functions: this is a tricky one. Require static analysis and everything. But progress is being made steadily! (Technically they work, but you can't access other struct attributes etc yet. Working on it)
Last edited: