Godot Tutorial Importing Data From JSON & Spreadsheet | Godot Inventory System Part 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
do you want to know how to get your files from spreadsheet straight into Jason and then ready for go to import then stay tuned that's what we're going to be doing today in the last episode we made the graphical user interface for our inventory system and today we're going to add functionality to it now before we can really add functionality we better have some items to mess around with and I don't really feel like adding those one-by-one and you shouldn't feel like doing so I so today we're going to be using a spreadsheet with all our items import that to Jason and then put that straight in to go to ready for future use now I'm here in my Google Drive to start this off today I'm gonna be using Google sheets as my spreadsheet program and the reason I use Google sheets is because I like the idea of all my important files like item tables loot tables monster tables you name it tables to be immediately saved to my cloud when I put them on my hard disk a my hard disk crashes I possibly get set back in my game development maybe months maybe even half a year that's the last thing I want so within this Google Drive folder I have two sheets I have an item table and a loop table let's have a look at them in my item table I have listed several items that I'm going to be importing into Godot through Jason for this tutorial in the real game it's gonna be much longer of course but for this tutorial we don't need 10,001 items in our loot table we have several map names that are going to be dictating what can drop in loot on that particular map now you can expand on this by saying special chests legendary chests specific monsters bosses you name it if you code it in this loot table you can put what that specific boss monster map chest can drop now before we continue let me quickly give you one quick piece of advice when you're naming these columns get a little bit of thought about that because these column names are going to be the dictionary names and the variables names within the dictionaries that are going to be used by you in your cold so having for example just a tack for the weapons could possibly become a little bit confusing when you start to code and you have ten different attack stats so in my case for my item table I like to start all my columns with the name item so I always name know where it came from now that we had a look at what the sheets are let's go over how we're gonna put them into Jason in Google sheets you have add-ons and I'm pretty sure you can use Excel for this as well and at Excel Microsoft Excel has a add-on for this as well I'm just using Google sheet for the immediate cloud synchronization function and I know with the new Microsoft is probably possible to it's just something I'm used to for Google sheets we want to be downloading export sheet data atom this is a free add-on just Google Google sheets export sheet data add-on download and you'll immediately get on the right website and you can add this to your Chrome web browser and it will be immediately available within your Google sheets in the web browser with that installed we can go to add-ons export sheet data open side bar now in here all the standard settings and there's quite a few of them are all gonna be immediately correct for the purpose that we have we only have to change one thing when you open the side bar what's more likely it says select sheets all sheets now it is possible to use that you might need all sheets in the future if you maybe want to create different tabs within your spreadsheet maybe a tab for all your armor items or your weapons or your crafting items you name it then at some point you wanna maybe export all sheets and then iterate through all those sheets within a JSON thousand and import those to go to for now we only have one sheet with one sheet we're gonna say current sheet only and we sell it to export it will compile the JSON file immediately and bam it's done already let's do that with our loot table as well so again add on expert sheet data open the sidebar set it to turn sheet only and export it will compile our JSON file and just a few seconds later BAM it's done within our work folder where we open the files from we now have two JSON files and these are going to be important to go to now before we're gonna be using these Jason's let's first prepare our project structure we didn't go to you can see that from the last tutorial I have created one more folder within our file structure and that is the data folder we're in the data folder I'll be putting all our JSON files so once you've added that to your game folder or your project folder let's go back to Google Drive and we're gonna be downloading these JSON files with them download it I'm going to my downloads folder I'm gonna be cutting them away and I'll be putting them within my go to project in the data folder I've already tested get one test run so I'll be replacing these and now we have an item table and a little table within our Jason folder within our data folder now that done we can go to go to and we can actually start coding to start coding we're gonna have to add our code to its script now to add a script to an existing node you probably know you have to push the add script button over here while you have a node selected however we don't want to add our JSON import code to our inventory node the reason why is that we want to be using this data within these JSON files for many more moments and many more reasons than just inventory we probably want to be using the items to end their stats specifically when we equip things and items and armor and weapons to our character in our character screen we want to have the loot table data when we are walking around on a map within our map scene so we shouldn't be adding them only to the inventory we basically want these dictionaries these pieces of data these data tables to be readily available whenever in the game and to do that you can add a singleton to go to a singleton acts a little bit like a global variable in other game codes to add this singleton to the game we're going to be adding a new script from down here in the file system it's gonna be a normal GED script I'm going for empty template now I'm gonna be naming our new script import data and now we have our new script here to make this the singleton to let the game know it should load this piece of script from the start and have it loaded all the way to the finish we're going into project project settings and we're going to the tap auto load now under all the load you open under paths the import GD file that we just created and you add this and as you can see here in the singleton column you know automatically sets enabled which means it is always available and it gets loaded even before any game node is loaded join the game starts now we open our script and I've prepared the piece of code for the item table data already so we're gonna be copy pasting that in here we're gonna run over it to see what exactly does so we understand it and then we'll be making the same piece of code for our loot table together so we create a new variable called item data and this is going to be the dictionary that is gonna have all our data from the JSON file and this item data variable is going to be the dictionary name that we'll be referencing in other parts of the code in our game now under the ready function which is a function which executes automatically the the game script import data is done loading into the game scene we define a new variable item day of thought and this variable is a of the type fowl and it's a new film now that item data file we open it using the reference to our item table sheet 1 dot jason within our data folder on our project file structure and we this we define it as a fowl and we read it this is very important don't write it you don't want to write over your data files of your game you always want to import them you never want to export out of them if you want to save your inventory will be doing that later then you want to create new JSON files and you want to store them in a different way on a different location now we create a variable called item data jason and we parse the JSON format that is within this file and we get that as a txt so we'll be using the item data file reference so we're using the same file that we're talking about here and we get that as text using the json.parse command now that item data file can be closed thereby saving our game resources we don't need that file to be open all the time that's not necessary and then we load that item data jason that we talked about here that we parsed the JSON as text into we equal the results of that to our item data variable that we defined up here thereby creating our dictionary now to test it everything went well what you can do is you can print that variable and because it is rather short we only have several lines now it's possible but the first time you do it is do this maybe with 10 lines in your JSON file or 10 lines in your excel sheet I should say or your Google sheet and use that to Jason in Court and then test it using this print command and then when you know this is going well you can pretty much guaranteed that it will work for many more lines of code as well now with that done let's do exactly the same but then for our loop table so we create a variable and it's going to be looted data we under the same function ready we create a variable called loop data underscore foul that is a foul new-found that's good data foul is going to be opened and we are going to use the reference that we have here but instead of item table we call this loop table [Music] this is of the type file and we read only with that done we can now parse the information within this file through JSON parsed and get the text back as text so far loot data Jason this is gone so this is basically just a temporary variable that we that we use is a jsonparser from our loot data wow we get that as text then we can close our loop data file to save the resources and then we can define the end result loop data as equal to loop data jason dot result with that done we can also print this dictionary to verify the results that we're gonna do right now to do that let's just make sure we have a little bit of a structure within our game you probably be adding this inventory to a game you have already been building you might have a map already I have absolutely nothing so I'm quickly going to be adding a new same custom note we'll be adding a new note here and we'll be saving this within the root folder let's go one up and I'll just quickly name this game root now within my project settings I'm going to under application run I will set that game root to be the main scene to run from and in here I'll add my inventory as a child so that it loads the import data script is automatically loaded because it's an auto load singleton so if I run the game now I should be able to see my dictionaries I see the child note right here from our inventory our graphical user interface that we make and down here in the output I can see that it has added the charcoal with no defense but some item weight there is 0.25 the iron boots and this is all gone alphabetically so these are all our items within our dictionary and we have our dictionary of grasslands with our item chances are in Mexico latina main quality the names of the items etc etc so everything seems to have imported properly and we are ready to go for our part 3 in which will actually be using this data to add some items to our inventory to mess around with I hope this was helpful if you liked the video put that thumbs up hit subscribe and add bail notification button so you get a notification for when the next part goes live next Monday if you have any questions put them down in the comments below or find me live on Twitch every Tuesday and Thursday where I stream my own game development I'm currently working on an RPG slash TCG gun again I'm really excited to get it out to market that's it for today I hope you enjoyed I'll see you next time
Info
Channel: Game Development Center
Views: 18,711
Rating: undefined out of 5
Keywords: godot tutorial, Godot import data, godot tutorial import data, godot json tutorial, godot tutorial json, godot import excel, godot import spreadsheet, convert spreadsheet to json, convert excel to json, godot inventory tutorial, godot inventory system tutorial, godot tutorial inventory, godot inventory, godot inventory system, how to import data from json, how to make an inventory in godot, godot, godot engine, godot game engine, inventory system
Id: MHeMxiDwo4o
Channel Id: undefined
Length: 15min 35sec (935 seconds)
Published: Fri Sep 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.