GameMaker Optimizing - ds_list question

Bee

Member
Hi all,
I have a matching game (kinda like match 3) and it works well. However, over time the game slows down. I've done some debugging and refactored a tonne of code, but it still happens. Later on, but it happens.

The matching creates and destroys a lot of lists, for every entry on the board. I was wondering if maybe creating global lists at the beginning of the game then filling and clearing them repeatedly during gameplay would be less resource heavy?

Also, some questions:
If I declare a var match_list = scr_create_match_list in a script, that match_list needs to be destroyed at the end of the script, right?
And if I do return match_list then ds_list_destroy(match_list), does the destroy run even after returning the value?

Thanks all!
 

FrostyCat

Redemption Seeker
If I declare a var match_list = scr_create_match_list in a script, that match_list needs to be destroyed at the end of the script, right?
Unless that value is returned to outside the script (in which case that external source is responsible for cleaning up the list when appropriate), you have to destroy it before the script ends.

And if I do return match_list then ds_list_destroy(match_list), does the destroy run even after returning the value?
A return statement immediately ends the script without running anything after it. This is one of its most basic properties.

Unless you strictly need the stretchiness of lists (i.e. frequent inserts and gapless deletes) or JSON compatibility, using arrays is almost always a superior, manual-cleanup-free alternative to lists.
 

Bee

Member
Thanks for the response! There were a few things I didn't know about lists that I've now figured out that have helped immensely.
 
Top