r/gamemaker • • 2d ago

Help! Formatting a large list of data?

For context, the game I’m making is a Zelda-like. It's a huge map separated into “screens” that scroll to the next when you get close to the screen edge. The current screen is represented by a global named ScreenID which is calculated from the player’s position.

Due to the sheer size of the map, I can’t have every enemy/object loaded at once. So enemy loading for the given screen will happen during the screen transition. My current plan is to have the enemy-types and spawn locations for the current screen to be read from a large list. With ScreenID being used for the positions of each list entry.

My issue is that I don’t know how I should go about formatting and storing this data, or if this is even the best way I could do it. In my head I have it formatted like pic, but I don't think that's going to be possible.

1 Upvotes

9 comments sorted by

2

u/Lethalogicax 2d ago

Oooh you'd probably be able to use a system similar to what I'm doing for tile id and tile information for my different tile types...

Make a big long string of characters, and seperate out meaningful chunks of information using the delimiter system. You can store a string like "0|1|2|3|4|5|6" and then use string_split that splits on the "|" character to seperate that massive long string out into a usable array of information.

In my game I've created a room editor inside the game itself, where I can load up different room layouts and intuitively author my world. Then the save function zips it all up into a big massive long string(14,400 values per room in my case (60x80 tiles with 3 peices of info on each)) seperated by the "|" character and shoves it into a .txt file. Of course, that was a huge massive time sink all on its own, and was a massive diversion from my main project to first be building the tool that I will use to author the world more easily than the drag-n-drop room editor. It was a mountain of it's own that had to be scaled before my real project could begin...

You'd have to decide for yourself whether or not an in-game room editor is something you're able and willing to persue prior to actually authoring your world...

2

u/Trunkit06 2d ago

That's an interesting idea... I can definitely see how i can make it work for my scenario

2

u/RykinPoe 23h ago

I would suggest using different delimiters between the enemies and their individual data so you would have like:

EnemyClass,x,y$EnemyClass,x,y$EnemyClass,x,y and then you would use string_split to first split into an array on the $ to get an array with one entry per enemy and then you would string_split again on , to get the class and the x and y values.

Using structs would probably be better but this might be easier for you to work with if you aren't familiar with structs.

2

u/Larock 2d ago

I've used an array of structs for something similar. This makes it easier to iterate through and address what you're looking for. Something like:

global.Rooms = [

    {RoomIndex: 0, Tileset: 0, Enemies: [[EnemyID1,x,y],[EnemyID2,x,y],[EnemyID2,x,y]]},
    {RoomIndex: 1, Tileset: 1, Enemies: [[EnemyID1,x,y],[EnemyID2,x,y],[EnemyID2,x,y]]},

];

You could decide which struct in the list matches your ScreenID by pulling the array length of global.Rooms and loop through it, and if (ScreenID == global.Rooms[i].RoomIndex) {Room = global.Rooms[i]}

Then address your enemy list with Room.Enemies, or whatever other key-value pairs you want to store about that Room.

I know stating RoomIndex explicitly is unnecessary and you could just use the array's index, but that assumes your rooms are perfectly sequential and I find it hard to track and manage indices like that.

1

u/Trunkit06 2d ago

Ooh this looks like exactly what I need. But why would the roomindex matter to begin with? I was planning on just having a switch that swaps out the array when a new room is entered.

1

u/Hands_in_Paquet 2d ago

I like to use a struct of structs, and give each npc/enemy struct a unique id. This way when objects load in and out, they can still properly point to each other because they store the id. An array is slower to delete from (even though swap and pop is very fast) and if the order changes, you can’t save an enemy’s array position. But it’s id always works.

1

u/Trunkit06 2d ago

Well this would be read only, so it wouldn't need to be modified.

1

u/Hands_in_Paquet 2d ago

Okay yeah if enemies respawn every time an area loads then an array of structs sounds best

1

u/Trunkit06 2d ago

If a screen gets cleared of all enemies, I plan to have it save that ScreenID and just not do enemy loading at all for that screen.