Do I use ds_lists? [SOLVED]

Ax209

Member
Hi everyone, looking for some general advice on the route I should take in order to achieve something. Something I've never done before. I wanna learn how but first I need to make sure I'm learning the correct thing. You guys are pros and no doubt know GML better than I.

So! Here's the deal. I'm making a little game and it has a management system involved. In said management system there's an ability to Hire and Fire staff, as well as manage them, train them and get them to work for you. Now, I'm looking for a means to add the staff, and show them in some kind of list in one of the windows. I've had a look at GMS and I *believe* I need to use DS Lists. Would you guys agree that I need to save this data into a list?

If so then yeah I'll go ahead and find some tutorials on that. If not then please advise what would be more appropriate. I've had a look at lists already and there is one thing that sticks out at me, it's the fact that the list is something I need to create, the GML Manual states that lists need to be used appropriately otherwise they can constantly take up data and crash the system with a "memory leak". Okay so I have to handle them properly, I can learn how to do that. But at what point do I need to destroy it? The longer it's in use, the more memory it takes up? Or do I just need to destroy it before I leave and go to another room? Can I only use it for a limited amount of time before it takes up too much memory? If I need to delete it, is there a way of saving my data and loading it back up again when need be?

Any help appreciated peeps! <3
 

obscene

Member
You may be better using a ds_grid which is a little more spreadsheet-like and supports multiple colums and rows. It sounds like you might need that if you have multiple things to store for each person.

 
M

Mholmes3038

Guest
You can build a list using a List or an Array. Dynamic Array would work but I'd recomend using a List as its easier to manage and add/remove. Plus List is becoming the industry standard in most cases.
 

Ax209

Member
Fantastic peeps. I'm looking into both, starting with ds_grids.

One question (kind of again). See, it tells me to delete the grid to prevent memory leaks. At which point would I need to do this? Can I keep it open as long as I want so long as I destroy it when the room/game ends?

If I keep it open as long as the "level" or room is in use, will it continue to "leak memory", or will it only use the memory that it has been allocated?

is a "memory leak" just when you accidentally open loads of DS_grids, and forget to close them, and perhaps you keep entering a room which has a creation code to and no code to close it?


LAST QUESTION (I'm sorry, but you guys are really helping), what's the best means to save a grid? Can I just save it to disk like I save any other data?

Many thanks in advance.


EDIT: Found the loading/save stuff, thankyou. Any info on memory leaking and destroying the grid, much appreciated!!!
 
Last edited:
W

whale_cancer

Guest
One question (kind of again). See, it tells me to delete the grid to prevent memory leaks. At which point would I need to do this? Can I keep it open as long as I want so long as I destroy it when the room/game ends?

If I keep it open as long as the "level" or room is in use, will it continue to "leak memory", or will it only use the memory that it has been allocated?

is a "memory leak" just when you accidentally open loads of DS_grids, and forget to close them, and perhaps you keep entering a room which has a creation code to and no code to close it?
It becomes a memory leak if you keep adding them without deleting them. This will happen in improperly constructed for loops, repeats, events that are repeated, etc., For instance, if you have a projectile in an action game create a data structure like a ds_map that holds its stats, you better delete that ds_map when the projectile is destroyed, or you will have a problematic memory leak.

If you have sort of 'durable' memory structures you keep using (I used many to store entity and item definitions), those aren't a problem.

Edit: I think the ideal solution to your original problem is actually to use ds_maps stored as strings in ds_maps. This can get a bit confusing if you are new to data structures and, if your game isn't going to be terribly complex, you can avoid this technique for now.
 
A

anomalous

Guest
data structures for basic use are pretty trouble free.
The process usually looks like this:
1. for temporary data structures, you create them, use them, then delete them, all in the same step/script.
2. for most other use, you create them in the create event, and they are used by that object until the object is gone.
Typically people do this by putting the delete ds command in the objects destroy event.
However, I think when you leave a room destroy is not triggered, so for any such a process, you could consider also including a room_end event, in which you put the command instance_destroy(), which then triggers the destroy event for any such object, on room end. (alternatively you may run a with/instance destroy on all "need to be destroyed at room end", which prevents the need for that extra event in objects, but you do have to catch them all!)
 
Top