I would like to see more examples of Structs, like which Events do we put them in or why was it necessary for you to remove the script function bracket? Will the Struct not run in the script if it is in the function? You need to understand that we don't have the same knowledge of how GMS2 works in order to use these tutorials properly. Basically, you should make a video on actual application in a game rather than showcasing what it does. We need to see what can be done with it in different scenarios like an RPG game, platformer, top-down ship flying, or shooter. I am currently about to make a ds_map array, this video just told me it was obsolete, so now I need to know if I should do Structs instead?
the only thing missing would be writing/reading of the structs in order to serialize the data.....but since you can write code within the struct to do that for you exactly how you want the data saved, I guess that's a tie? lol Personally, I've always hated ds_map, it never was versatile enough to store huge chunks of data, and small chunks are easily stored as arrays or other forms....so it became pointless for my style of programming. I used to create huge data storage within arrays, using double-linked list programming within them to make fake "allocate" and "free" code to use them (it would return the array position to store data that you allocate space for)....when buffers were introduced, I switched to using that instead....and now structs are here, so I've already converted all of the code for it. I am loving structs....only 1 thing that would really make them the best, is if they had a deconstructor function, and the ability to free itself from memory within its own code without getting an error (maybe add itself to the "free me" pointer list behind the scenes for the next game step instead of actually deleting the memory at that moment).
Destructor methods would be really nice, in case you needed to free a data structure or unload a sprite or something whenever a struct is freed - although apparently that's not in the plans for the foreseeable future, which is a shame. For the time being I just give things a Destroy() method and call it myself when needed. Also, here's a video on de/serializing them: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-3HWe4vwU6TU.html
I've recently purchased GameMaker again after not having used it since around the time yoyogames purchased it-- I was delighted to see addition of structs. Besides the absence of hard crashing when using the $ accessor, are there any other technical differences between using struct[$ variable] versus struct.variable?
Nothing major. Variables can get syntax hightlighting so it's usually easier to see if you misspelled something with struct.variable_name than it is with struct[$ "variable_name"], though.
GML is a slow interpreter, however, have you thought of using the YYC option instead of the VM? All my games are compiled natively witch is known to perform better!
There's still a lot of overhead. Variables in GML, for example, are actually structs containing things like the data type (float? int? string? array?) and a value (number? text? pointer to the actual array?) and a few special-purpose flags, which is faster than interpreted code but still takes more time to process than something written in pure c or c++. If the VM is 10x slower than native code, the YYC might be 2.5x or 3x. Anyway look in the YYGML header file in the runtimes folder if you're curious about some of the inner workings. If you know your way around it, there are a few edits you can make to the generated c++ to speed it up further.
@@DragoniteSpam I don't fully understand how that works though, you can't add "key/value" pairs at run time can you? If not I can't seem to wrap my head around why one would not use dot operator and if you can add new members to the struct at run time I would love to know how. I currently am using structs for a Vector library but am running into issues with performance being at least 2-5x slower when attempting to return a new struct from my arithmetic operations. Such as C = A + B; I have to return a new Vector for C or I need to do A.add(B) which is far from ideal as it alters A, something you do not generally want. Anyway, better understanding of the internals of how structs behave in GMS might give me a better idea how I can improve the performance because I still can simply not use structs for anything high performance because they are simply to slow :(