#Advanced save/load question

10 messages · Page 1 of 1 (latest)

clear scaffold
#

Hi there, I have built a game where you can construct walls and different structures. Everything works perfectly, but now I am at the point where I want to try to save the built structures.
What is the best way of doing this? I have considered saving a ds list but am pretty new to them. Just looking for some guidance on where to begin with this, and then the process of loading and spawning these previously placed structures, through multiple rooms.

night mauve
#

no ds_lists (or ds_anything)- that's 1.4 era code

look into structs and arrays.
Put simply an array matches integers to data.
array[1] = 15 matches the number 1 to the data 15

structs match words to data
struct.a = 15 matches the word "a" to the data 15.

now, i assume this is a 2D grid, which means you'll need an array inside an array, so that you can match two numbers x,y, to data

array[x][y] = 15

#

the nice thing about structs and arrays is that they translate directly to json files, which is a file format that you can save

#

(structs are good for saving, like say "score", or "hp" for example)

#

for saving and loading you'll essentially loop through your grid with a double for-loop, and translate them to your array
and the reverse is true, to load your grid, you loop through the array and spawn the blocks appropriately

#

if it's not on a grid

you can have each item submit themselves, their object id, position, and any other data

and upon spawning, loop through your array and spawn the item at the position stored and with the data saved

#

A short tutorial about the new updates to arrays in GameMaker Studio 2.3 in the Coding Fundamentals in GML Tutorial Series.

Patreon Support
https://www.patreon.com/samspadegamedev

Github Repository (Source Code)
https://github.com/samspadegamedev/YouTube-Coding-Fundamentals-in-GML-2.3

Links:
https://manual.yoyogames.com/GameMaker_Language/GML...

▶ Play video

A short video with an update for arrays in GameMaker Studio 2.3.1 as part of the Coding Fundamentals in GML Tutorial Series.

Patreon Support
https://www.patreon.com/samspadegamedev

Github Repository
https://github.com/samspadegamedev/YouTube-Coding-Fundamentals-in-GML-2.3

Links:
https://manual.yoyogames.com/GameMaker_Language/GML_Overview/Arr...

▶ Play video
#

https://www.youtube.com/watch?v=R84mR52QaMg a video on saving and loading

the important takeaway for this video is that you make a big struct that stores all your data, and save and load that

Like the other tutorial I did, only better. A universal approach for when you need to save or load data in GameMaker, using JSON, structs and arrays.

▶ Source code: https://www.patreon.com/posts/44109513
▶ Support my work: https://www.patreon.com/shaunjs
▶ This same tutorial for older versions of GameMaker: https://www.youtube.com/watch?v=QmxQb...

▶ Play video
clear scaffold
#

Okay perfect! Thanks for all of the info and sources. I’ll do a deep dive when I’m off of work. I’ve already got the whole game saving to a json, so I should be able to add this into it, correct?

night mauve
#

no reason to make a second json haha