GameMaker New Data Structures Series!

Aaron Craig

Member
GM Version: 1.4 & 2.
Target Platform: All platforms.
Download: NA
Links: https://www.youtube.com/playlist?list=PLwfY1MeupeNYy9nvS5jjtQ8B9qo3hQHFd

Introduction to Data Structures //I'll be going over what data structures are and why you shouldn't be afraid of them.
Introduction to Arrays //Two part video, going in depth on 1D arrays with code and examples. Then covering 2D arrays with code and examples of for loops iterating over arrays.

Projects on Google Drive

Summary
:
Starting a new series on data structures in GameMaker Studio. The intro is up, and covers the basics of data structures in general, with some examples that include real life data structures. I'll be going over each data structure with in depth discussion and examples.
 
Last edited:

FrostyCat

Redemption Seeker
For a for-loop-centric tutorial, above all you should be the one leading its proper use. Unfortunately, you aren't. Using the instance scope for temporary values like looping variables is an often underplayed bad rookie habit, and I'm disconcerted how little awareness of it there is about when it bites.

This is the way you're doing it:
Code:
for (i = 0; i < array_length_1d(menu); ++i)
This is the way it's supposed to be done:
Code:
for (var i = 0; i < array_length_1d(menu); ++i)
Or better, save the return value in a local variable:
Code:
var isize = array_length_1d(menu);
for (var i = 0; i < isize; ++i)
I also propose that you inspect your project in the debugger's instance scope panel, once with your original loop and once with my loop. Your i sticks around taking up room, mine cleans up after itself. Think which one you'd rather look at in a more complex project where there may be many more different temporary values building up from various function calls.

As a Q&A responder, I've lost count of the number of rookies claiming data structures are too hard. I'd love it if your videos could get them to shut up. But if it means they'll learn the no-var habit along the way and make a pig sty of their instance scopes, I'd have reservations about it.
 

Aaron Craig

Member
For a for-loop-centric tutorial, above all you should be the one leading its proper use. Unfortunately, you aren't. Using the instance scope for temporary values like looping variables is an often underplayed bad rookie habit, and I'm disconcerted how little awareness of it there is about when it bites.

This is the way you're doing it:
Code:
for (i = 0; i < array_length_1d(menu); ++i)
This is the way it's supposed to be done:
Code:
for (var i = 0; i < array_length_1d(menu); ++i)
Or better, save the return value in a local variable:
Code:
var isize = array_length_1d(menu);
for (var i = 0; i < isize; ++i)
I also propose that you inspect your project in the debugger's instance scope panel, once with your original loop and once with my loop. Your i sticks around taking up room, mine cleans up after itself. Think which one you'd rather look at in a more complex project where there may be many more different temporary values building up from various function calls.

As a Q&A responder, I've lost count of the number of rookies claiming data structures are too hard. I'd love it if your videos could get them to shut up. But if it means they'll learn the no-var habit along the way and make a pig sty of their instance scopes, I'd have reservations about it.
You're absolutely right. I hadn't considered that, but it's important to do even the little things right. I looked at your example of recursion as well, which makes total sense. Although I don't see much recursion inside of GMS, it's still important to always be coding properly. I'll address that in my future videos, and start changing that myself.
 
Top