GMMeetup #7 - Juju Adams - I Love Data

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
right ello hommes so over this weekend I have been doing some Sony ps4 stuff so I've had a really horrible weekend so far this is literally my high point is talking about data because I love this stuff I'm a technical programmer that's different to a gameplay programmer that's different well to what most people think of like making gameplay mechanics and programming is making the person jump right I don't deal with that stuff anymore I've transcended to another plane also known as systems programmer as well so when I see games you know games are made up for these things and other things as well I don't see this stuff anymore I see data I see numbers mostly and occasionally some letters I worked on this game for benefit of people who don't know me I watched my black drifter I did database stuff I did optimization and work in that regard I can't direction Firefly drifter and I'm now working on the sword of ditto which is being published by devolver and it's being released on the 24th of April please buy it well yeah the the QA testing is gone really well so far so hopefully it's gonna be a good game early so today we're going to learn how to make a safe file I'm gonna look at two methods one is gonna be really really good one's gonna be really really bad and it's gonna be like using an example that's bad to show you how to make it better again hypo light drifter did it the bad way all right I didn't get round to fixing it couldn't have time swords Edisto I learned from my experiences and we did it the good way and it is much more reliable in fact we've had no bugs since I implemented it back in October so first of all nice all about data storage in game maker you have no idea how excited I am about this seriously okay even in animations is great I think the first like the fundamental unit of data structures is arrays hopefully when I want array is I'll go over it very quickly in a second and alongside of rays we have D s lists I move data grids now you might not have seen these before especially if you haven't used game maker before well there's other things called es maps as well down here and there's kind of other DS's D S stands for data structure it generic term that game maker uses for stuff that's more complicated an array it's a way of storing data in a way that's more complicated and array more flexible there are other ways of storing data as well buffers and surfaces but we're not going to really talk about those so much because I'm more interesting what a a belated data so arrays lists grids you can represent them as tables tables of data you can think of them like that and down here we have dears maps and just lists also form a little little partnership at the Run which is called JSON I'll tell you what JSON means in a second it's very exciting it has no bearing on anything in game makeup and it's really cool anyway and we're not gonna talk about these at all because they're way too complicated way to advanced outside the script let's talk the data storage message that these represent are interesting so I do encourage you to look into them so we can take it slow first things first tabulated data 1d arrays it's just a it's a column on our spreadsheet people spend so much time talking about arrays and they never do it right it's just a column you have a thing here and a thing here and a thing here and thing here the array is the whole the whole column right that's it that's it it's no more complicated than this you can refer to each cell by using a number which refers to which row it is of your column in your spreadsheet but just listen 1d arrays are equivalent right so if you haven't used GameMaker before you're not familiar with TS lists you can think of them as the same thing as arrays and in fact that's how you deal with arrays so you get data in and out and yes let's look very very similar so we have the storage unit here which is an array who have storage unit here which is a list they'll have the index I index I down there and then we have the input and output values so they look very very similar in fact they operate very very similar as well notice I'm you to replace not add people you need to go make a replace allows you to refer to a specific element whether it's add just kind of sticks on to the bottom 2d arrays like 1d arrays they're just a spreadsheet just think of it as spreadsheets that's all you need to do in your minds when you talk about like theoretical things like arts you know it's pointers to information and you access the pointers ignore that it doesn't mean I care about it just think about it is 2d data on an Excel spreadsheet and it turns out the deert grids and 2d arrays are very very similar as well like 1d arrays and similar 2d arrays and grids very similar so here we go let's I deal with a 2d array that's how you deal with a grid you can see that the XY coordinates which is U Rose new columns we con suppose work the same way in both grids and arrays so since they're so similar arrays and these data structures listen grids you might be asking why we use them DS lists dears grids give you lots of extended functionality it's really exciting what you can do with them so exciting gonna show you why the thing is that that arrays are great as well they do have a use but if you try to implement some of this stuff it's kind of a pain in the ass right so here's how you put a value in the middle of an array so if you've got if you've got this data here and you're trying to stick it in the middle of an array that's the code that you have to do to get it to work properly and notice that I'm using this weird little app symbol here which is called an array access er don't worry about that this is complicated you have to do that in a script and it's manual in it's slow if you want to do it with the list it's one line of code that's it it's really simple right okay how do you delete a value from an array you'd have this you have two for loops and then you can't even access the change the array in City right you have to return a new array and reassign it which is really unintuitive and it's crap and go makes a real pain with arrays D s list it's one line of code this is why we use data structures so it begs the question why bother with arrays then if data structures that much better the answer is data structures have this weird dark side that make me very uncomfortable and is the source of like 50% of bugs and swords of data memory management in comics ons for extra horror I think this is best illustrated it's an example I'm going to repeat this a bazillion times we're going to create an array fill it with data this is a cool feature in GMS - by the way get GMs - you can create array literals so you can just create an array in code rather than having to do like create the array and then assign each individual value and then what we're going to do is take the array variable and assign it under assign to it undefined what this does is it takes the array NIT dumps the memory deallocate sir again making knows that you don't use it anymore now here's another example Peter a bazillion times create a list fill the list of data get rid of the list this doesn't work it doesn't work at all so what we're doing here is we're setting the array variable here to be undefined so dumping that data changing the datatype what's happening down here is that it's kinda hard to see actually isn't what's happening here is that this variable here list is referring to a location that the list is stored there's kind of complicated so when you change the list to undefined you're not changing where the list is stored over here you're changing your reference to the list so that means that that memory is still there you still got the list sitting in memory precisely that's a fantastic analogy now we can get rid of the draw oh hang on hang on data structures are like resources like drawers so for every data structure that you create you have to have to have to destroy it otherwise you end up with a memory leak if you get enough memory leaks then it crashes your ps4 builds and makes you really sad on a Sunday morning but we have to give a talk so the way you solve this is that you put in this wonderful line of code here just let's destroy that's it so every time you use a create you have to create a destroy can't command as well so you have to create and then destroy this will solve your data structure problems say files I promised it and now we're going to go do it say files require a bit of thinking first so before you write complicated code sit and think about it number one you slot the data into your into your DX squared right that's pretty straightforward right you've got a plan you put your data into the grid way we do this is we use one row per instance and one property per column so if you think about it we have each instance being a row and then each property is on the column it's like a spreadsheet rows columns let's say the first comes the object index next one's the x-coordinate next one's the y-coordinate fine next instance BRR sits a nice table beautiful simple and what we're gonna do is once we've built this grid we can use desperate write which is really cool function not many people know about it but disk would write allows you to turn a grid into a string so then what you can do is take take the square string and just stick into a file there's no normal string writing function for a file now as it turns out secret spoiler warning disk could write some work very well so this function here is kind of trash unfortunately has a lot of bugs so I ran into this and the reason why we changed the same system for sorts of discos because I ran into a bug with good right where in some cases you put data into it and it would not be the same when you got the data out of it so that really screwed everything up that is a bug though and that's not how its intended to work so imagine it does work and imagine it's perfect this is what our table looks like it's a spreadsheet here's two instances of object tree here's another instance of object n piece of objects NPC and then we've got some data over here for a sec some y-coordinate simple here's the code that does it and I'll let you take that in for a second all right okay that's some code what does it do all right fine initialization stuff users and scripts it's getting the file name initializes the grid down at the bottom turns the grid into a string destroys the grid destroys the grid very important always take care of your memory issues so that's kind of bracketing the meat this is the meat of the function first of all we're going to go to every save parent so imagine an object's inheritance system some kind we're saving all of these objects we've got this iterator variable I and every time the loop completes it iterates and what this does is it means that this variable over here not sure we can see that necessarily on the camera but there's I over here so for every time you go through to another instance it goes to a Nero first line of code or the first pair of lines of code here is that we get the name of the object and we stick it into the grid column zero and again the x-coordinate stick in column one and the y-coordinate column t it's easy it just makes this man that's great isn't it like look at this this will save your entire game that's it Oh fortunately I don't were like that because it total crap doesn't work doesn't work because any time you do something more complicated that needs more than just a few variables let's say you want to save an array you just can't do it it doesn't work you end up with this really complicated system are you getting a raise and sticking them different places and trying to refer back to the money you tie yourself in knots to solve a problem that was in the inherent in the design stage there are some key issues format changes you're screwed so if column one you decide not long can you see the object name it needs to be lines of dialogue the whole thing breaks if you have different objects that need different properties you'll end up putting variables in different locations which might have different meanings in different contexts and that is a nightmare to debug and finally disk read write doesn't support nested data structures so you can't go back to this table here and put in arrays here you can't make this an array you can make this a list you can make this a grid within a grid so if you're trying to represent complicated structures that have depth to them like a game does you just can't use this basic method so there's gonna be a better way okay it's JSON this thing it's incredible it's gonna change your life maybe not but it's it changed my life okay so JSON exists down here JSON is a pairing between a D s list the DS map we've done D s lists remember they're 1d arrays they're like a column of data D s Maps away different the S Maps kind of blew my mind when I learned about them these are called hash tables or dictionaries for people who are familiar with those so we can think of a list as data in a nice line and they go sequentially 0 1 2 3 4 5 6 dance if you wanted to maps look like this they look like slight rendering bugs that novi computer home maps are unordered they kind of happen in a pile they happen in a puddle the way the maps work is that you have keys that are associated with values every key has a value key Valley key Valley right yeah I can't bake no good at cooking um [Music] take pictures if you like so you have keys and you have valleys fine the s maps are unordered though so the the order in which you have your data you know up here we have baking skills down at the bottom where they deserve to be and then my name at the top where it deserves to be um he doesn't matter what your and he actually put these these things and you can find these data this data stuff by looking at strings so you go to the yes map and you say I want to find what job Jun and Adams does he does a job it is game maker nice and simple so actually turns out that you can have your data like this like this like this any doesn't matter these are all the same it's all the same dears map in fact when you put stuff into a DS map you have no way of knowing or order these things actually going in which is really interesting sounds not useless but it sounds of limited use turns out in my opinion this is more useful than a TS list by far I'll tell you why but first this is how you use them this is how you put stuff into a map so you add to the map you add your key and your value and when you want to find stuff obviously you only need the key so you put the key into the function and it gives you the output value also dears maps have this wonderful feature where you can tell if a key exists in the DS map just by looking at the key itself if you want to do this in the list you need yes lists find index so people who know this and if it can't get make it can't find your value in the list then it says negative one rather than a normal value it just tells you negative one the thing is that if you need to find something in DS list it needs to go through every element that is what we call o n complex that means worst case you need to go through every bloody element in a DS map is o1 complex it only need to look at one entry to see if something exists this is handy so dear some maps I've seen used by many many people and I've seen them used wrong by many many people so here's some guidelines so you don't do the same things make me angry Keys should always be strings GameMaker lets you make keys for DS maps and not strings please don't do that because it means that if you try to debug it you have no idea where the ring is meant to be a string or in and when you serialize things using JSON spoiler warning if it has you're gonna say a point in a second no you just okay okay um so if you see revise something into a JSON it makes everything a string so if it expects it to be a number and it turns out to be a string you're gonna have to debug that so just make them all strings anyway it's more useful Thurl strings try to avoid iterating a VDS map I told a little white lie earlier you can actually tell what what the stuff goes in but it's incredibly slow I think it's o n log n cut off my head complex which is really bad so try to avoid iterating up des maps if you after you have to actually I can't remember maybe it's oh it's game I command gonna be honest I've done of what they're doing with the hash table in the background because they're allowing you to use real valued keys for your home for your dictionary I have no idea what they're doing the backend so I have to go ask Mike daily and he'll tell me to go away I'm sure I've got a record isn't it yeah so dear sir maps are not replacement to tabulated data so you can't use a dsm app we shouldn't use a deist map to replace a list or a grid or a array because as soon as you try to remove an entry from the middle of a TS map and you expect all the values to still be sequential isn't gonna work anymore and finally I've seen people do this and I've tried it myself do not make them replacements for actual objects and instances you can do that because if you I'm not gonna go all the way back but you can all right JSON comment oh so you couldn't sense each value you can look at as a value of a variable and each key you can look at as the name of a variable that means you can kind of simulate an instance by using the keys as variables each entry and just map as a variable don't do that's it's really slow its way slower than actually using instances and it's really complicated all right JSON yes does it loop forever I hope it does Jason stands for JavaScript object notation so this is an industry standard mostly the web services especially used to communicate data to each other it's very very compact it's very very nice and I'm see we don't care about the name because we're in gaming so JSON is a way of expressing data as a tree rather than as a table so this requires a bit of imagination because we were been talking about kind of you know tabulated data like flat things that you can kind of imagine kind of playing around with JSON is a bit more complicated it's still ok because even I can make diagrams of this so this is a tabulated data everything's nice and neat and ordered and since you take away this row that's where it comes across so Conrad and it's kind of nice right JSON is much messier like this part of Zampa this is this is some kind of JSON things so stuff branches and things can have different amounts of data and you can branch again inside of a branch and this could go on infinitely you can have this infinitely deep JSON some people have used JSON as a way of making virtual machines incidentally JSON tree for us not for the other people in the world us-a made using des maps des lists nested inside each other in some way to describe whenever you trying to describe so if we look at a DES map from before I'm gonna put some more information in it using some lists and using a DSM app so these this here is the original des list this is what we had originally and then inside each one of these keys I put another list put another list and I put another map and you can do this infinitely you can keep going for as long as you want and this allows you to do some really interesting stuff so let's say you want to have a list of all of the instances and then instances have children and then the children have links to other things inside of your structure you can do all of that with the JSON you cannot do that with with any other data type really at least you'd have to come with some crazy format you might as well just use JSON so if we're gonna look at this particular structure here as a JSON it will look like this so this is my name this is my age this is my job this is what else yeah my hobbies and this is my skills once you start thinking about stuff data there's trees and Jason's you start seeing how to lay the stuff out stuff like save files go might give us some native functions and equipment few words on these these are the only functions need to know for using JSON beyond the map disk this stuff unfortunately whoa whoa whoa what's going on here man that's not like anyway never mind ignore this I know this stuff doesn't exist these functions down here are kind of broken much like the sliders these functions don't really work the way you expect them to this is much more natural you put stuff into a map and you know what type it is these ones for some reason these two down here work a little bit differently for some reason I don't know why they were made like that and also this function JSON encode only works if you've got a DES map as the first element in your note if you have D s list this doesn't work so well because of the way game I could stuff until me anyway fun fact you can clean up de structures really easily this here you've got stuff nests inside stuff and then you destroy it and it all disappears completely it all gets memory managed for you so JSON is cracking means you don't worry about any memory issues oh did you load up the ODT version or the PowerPoint one weird anyway this is miss a serialization part two it's a really good joke and it's totally blown it anyway so let's start with a DES list let's think about this we've got our game it's full of stuff rank all this a guardroom it's full of stuff let's make a list of all that stuff and each thing that we find in our room you can add it to the list as a map and we can have one map for everything that we find for every instance that we find and then inside the map we're gonna have each variable there's gonna be a key and each keys value is gonna be the value of the variable that we find that describes everything that we'd want to save you can even do this with lists so he could find lists in instances and attach them to IDs map and it would still serialize because that's how Jason works right you can put a list inside them outside the list so it's gonna look like something like this where each group of data is an instance each one of these is an instance in each circle it's a variable it's nice what sir means that if we need to have different amounts of variables different outs of entries for each instance we can do that it's add more stuff on if we need to nest it in a different way if you need to put more information it you can just do that totally natural let's do it let's make the system it's quite a list I'm gonna iterate over everything one for everything I'm gonna make yes map I'm gonna add that to the list then we're going to make sure that game maker knows that the thing that we just entered which is the size minus one zero indexed I'm gonna make sure that that game I can know that's a map and then inside that map you're gonna put an object's its name which we get from this function the object your name you gotta put its excellent and it's why corn and I was gonna do everything in the game and then we need to do some faffing around because as I said JSON encode doesn't like lists it's the first node so we're going to do it with a wrapper so we're gonna put all the states we just found you can put inside a map then we're going to kick out everything is a string then could've put the string into a file I've kind of hand wave this a little bit I'll show you that script later it's very simple and then what's the most important step destroy the data structure make sure we destroy the map wrap and because we have mapped sorry because we have placed the list inside of the map that means when we destroy the map it stores the list then it destroys everything that's inside the list as well that's it and missile e there's a little bit more complicated than the grid base version but this is really flexible this is great this will take you far this is house or editor works house its office so going back to the three points that we raised about tabulated data about disk words if the format changes all our fuzzum is immediately useless for desk words or for json doesn't matter because the context of each value is stored in the data file it's stored in the same file we know exactly what each instance holds because we're told that by the key that's fantastic so we can just do whatever we want with the json this is way better than a grid what about different objects and different setups that we need while for a dish grid we need to do that with special cases it's still kind of nice to do that with JSON but we don't need to worry about the size of grid or like how to best pack in our data to make it more efficient we don't need to worry about like I have to organize it make sure that it's clear and unambiguous and we just don't you see that with JSON it's a soft eye problem instantly and finally ditch good right which as we know has a bug but disk read/write doesn't support complex data well with the JSON do you another how do you want to nest stuff as long as it's a DSM app or address list so they need to bear that in mind bikini whatever you want with the JSON and if you have any arrays you'll need to send them into lists when you put them into the data structure if you have grids you need to do a list and then list coming off the original you can serialize that as well that's it JSON solves all of the problems with yes grids and he does it in a way that is frankly kind of about the same amount of code so in conclusion I'm sure you've all worked out really like data and JSON is way better than desk words this is eighty-eight slides well done for sitting through thanks very much I'll put out the slide so you can have a look at the scripts thank you you
Info
Channel: Shaun Spalding
Views: 8,044
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GMS2
Id: Uj7nr6vSRvs
Channel Id: undefined
Length: 25min 38sec (1538 seconds)
Published: Tue Apr 03 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.