Hey!
I'm creating this thread for posting tips, tricks and random knowledge that may help GameMaker users. Users can look here and read the posts by our amazing members and learn awesome stuff!
I also have a page like this on my website, which targets beginners: Link
--------------------------------------------------------------------------------------------------------------
I am posting Tip #7 from that page here.
Post your tips here. I may post some of them on my website if they are for beginners, but well, let's keep those things to this thread for a start.
Thanks!
I'm creating this thread for posting tips, tricks and random knowledge that may help GameMaker users. Users can look here and read the posts by our amazing members and learn awesome stuff!
I also have a page like this on my website, which targets beginners: Link
--------------------------------------------------------------------------------------------------------------
I am posting Tip #7 from that page here.
--------------------------------------------------------------------------------------------------------------GameDev Palace said:In this tip, I will address something that creates confusion for beginner developers.
I am talking about the _create functions. These are functions you use to create something (surface, buffer, data structure, etc.) and store the result in a variable.
Let’s take a DS list as an example. The function creates the list and stores it in the variable, right?Code:surface = surface_create(args); list = ds_list_create(); buff = buffer_create(args);
So this way, if I create the list in a local variable, it will be gone at the end of the event, because the variable is local. Right?
Actually, that is not how it works. Whenever you create a list, it creates it inside the memory. That is where the list exists. The function just returns a pointer that points to the list inside the memory. So the variable you use as the “list” is just a pointer which allows you to access the actual list in the memory.Code:var list = ds_list_create();
So, even if the variable is local, the list is not. Remember, the variable is just a pointer. So to destroy the list, you have to use:
This function will remove the list from the memory.Code:ds_list_destroy(list)
Also, when you do this:
You’re not creating another list called “list_2” which is the same as “list_1”. You’re just copying the pointer value to that variable, so both of these variables point to the same list on the memory.Code:list_1 = ds_list_create(); list_2 = list_1;
So this is the same with the other things, like surfaces, particle systems, and buffers. The variable is only a pointer to something that exists inside the memory until it is destroyed.
Post your tips here. I may post some of them on my website if they are for beginners, but well, let's keep those things to this thread for a start.
Thanks!
Last edited: