I'm coming at GML from a C++ background, and I want to have some global state to represent my player character, their inventory etc in an RPG game I've started. I really want to know whether it's possible to create an "array of structs / objects", similar to the following (C++):
It seems like the only way to get close to this in GML is to create an object type with some defined variable names, create instances of these on a layer, and then loop through these using "with" or similar. Whilst this is fine within a single room (using a layer of a depth over 16000 which isn't rendered, one per object type), I'm not sure how to do this for state which is global to the game. I wonder if I can use the persistent layer/instance property?
On top of this, are there any sorting algorithms outside of the built in alphabetical list sort? For example (C++ again):
Apologies for all the C++! I'm hoping a lot of this will be rendered moot by the coming GML updates, but in the mean time I'd still like to know how this kind of thing has been done in GML over the years so I can continue with my game.
Code:
struct Item
{
std::string itemName = "Name";
ItemEffect effect = ItemEffect::kSomething;
};
std::vector<Item> items = {
Item { "Health", ItemEffect::kAddHealth },
Item { "Weapon", ItemEffect::kIncreaseStrength }
};
for (const auto& item : items)
{
draw_text(item.itemName);
}
On top of this, are there any sorting algorithms outside of the built in alphabetical list sort? For example (C++ again):
Code:
std::sort(items.begin(),
items.end(),
[](const auto& item1, const auto item2) { return item1.effect < item2.effect; });