Advanced Godot | Integrating Nim Into Godot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is mitch with fine point cgi and today we're going to talk about how to integrate nim into godot so we're going to go through the process of talking about what nim is and why we may want to use it and then we're going to go ahead and download and install nymph and then we're going to grab the stub project and i'm going to go ahead and show you how to set up the sub project and then i'm going to go ahead and show you guys how to build it from scratch without using the stub project although we still end up using parts of the stub project because there's there's no other way to really do it and then finally we run that inside of godot so that's what i have in store for you guys today so let's go ahead and get started okay so the first thing we have to answer is what is nim well nim is a statically typed compiled systems programming language [Music] and that's a lot of words so what does that mean well it's a lot like c plus plus and c sharp and rust right so it's a compiled language that compiles down to a binary that we can execute at a systems level like c plus plus or like rust so that's really great because it's very performant and it's very like extremely quick you know it's almost c plus plus or better than c plus plus levels of speed it has a very simple syntax it's very python like so when you look at the code you're going to be like oh it looks like python or like gd script and it supports all the major operating systems which is awesome and it saves a lot of time so what does the code look like well this is what the code looks like and you can see it's a lot like python in the sense that when you call out your functions you call them methods and you more use indents than curly braces to use your code and it's actually a pretty cool system um a lot of it is very python-esque so if you were to do a for loop you can look at it and see i mean it's a for loop it's very similar to what you would expect you use the colons and the things that you would do with python so it's very similar to python in its structure so now that i've at least given you guys a somewhat basis of what nim is like i said it's basically just a c plus like programming language let's go ahead and see how we can integrate it into godot so the first thing we are going to do is we are going to go ahead and install nim so we have to go out to their website which i will leave a link to in the description below and then go ahead and click on install nim and then go ahead and click on windows in my case if you have unix you're gonna have to go through the unix install and i'm gonna click on windows here and instead of doing a manual install which is the first option here and the most tantalizing one let's scroll down to installation using choose nim choose nim is a installer that just installs nim for you so we don't have to go through all the process of setting up our path variables or anything like that it just does it so what i'm going to do is i'm going to click on choose nim and it's going to take me to a github i'll also leave a link to this in the description below so that you can just go ahead and pull this right here and we will go ahead and go up to their releases page which is right here click on here and then scroll down and go ahead and grab the windows amd 64-bit edition and let's go ahead and click on that and if you want you can grab the linux or mac version if you would rather so that's going to go ahead and download and it is done so we're going to go ahead and go out to my downloads folder here and you'll see that i have choose nim right here so i'm just going to type cmd up here and open up a command prompt in that location then we're going to type choose nim enter and you'll see that it's going to give us a little bit of information here okay and we need to go ahead and just pull down the stable addition so we'll do as well do choose nim stable and you'll see that it's going to say hey can we have some telemetry data that's up to you guys i'll go ahead and give it to them because it's an open source project and it's going to go ahead and download all of your compilers and everything for you so it does everything and it's fantastic so i'm gonna let this go ahead and do its thing and i will be right back and you will see here that we have a failure and the reason why is because operation did not complete successfully because the file contains a virus or potentially unwanted software now this happens if you have windows defender enabled on your machine so how you can get around that is if you open up windows defender you can see here once you open up windows defender you can go to virus and threat protection and you will see protection history right here if you click on that you can see if they have any threats quarantine you can see that i have one so let's go ahead and stop that from happening so if we click on the down arrow you'll see that's gonna pop and say hey what you know are you okay with um you know making changes here yes i am and i'm gonna go ahead and restore this and it's gonna yell at me again and then i'm gonna do the same thing for my other quarantine which is my action to execute it so let's go ahead and restore that as well and that should now if i go ahead and attempt to do it again let's see what happens and you will see that it failed again right here it looks like it's the same exact issue so if you come into your windows security you'll notice that i have another threat blocked i'm going to click on that down arrow again actions and then we are going to go ahead and allow it now the reason why you have to do this twice is because one is for the actual file and then the next one is for the action to execute the file windows is trying to be protective but it doesn't need to be so let's go ahead and minimize this let's try this one more time okay and you will see here that it says switch to nim 1.4.8 that's awesome that means we have nim installed so that's great that's our first problem out of the way now from here we need to go pull down the nim project for godot and i'll show you two separate ways to handle this you can either build your own or you can use the stub project that already exists and i'll show you two separate ways to handle this so the first thing that we need to download for our stub project is the actual stub project itself so you can see here's the stub project if we click on the code and we go ahead and copy it we can go ahead and open up our command prompt and let's actually find a location so i'm going to cd dot dot and i'm going to cd into my documents and i am going to go ahead and make dir nim and then i'm going cd into nim and then i'm going to go get clone whoops not cloned clone and i'm going to paste that in here all right so it is just pulled down nim and if i go into here i go to documents and i go to nim you will see that there is my nim stub project which is awesome and i'll explain more about this in a minute but that's great it does a lot of the work for us now that we have it to this point let's go ahead and see if we can compile it so we're going to cd into godotnim and we're going to try to compile it so the easiest way to compile it according to their documentation is with a naked file you can see this little naked file which is like a nim make file and we can type nake build but you'll see that it says hey nake is not a recognized as an internal external command and the reason why is it's not installed with nim by default you're gonna have to install it yourself so what we need to do is we need to say nimble install nake interesting normally i have nimble installed let me see if i open up a new command prompt interesting interesting let me look at my system environment variables so let's go ahead and take a look at that let's see go into my path let me edit that scroll down uh see i'm missing some of my paths here you can see how i actually don't have any paths here so that's something that's missing it looks like it didn't install that correctly so what we need to do is we need to install our path location so what we can do is we can go new and we need to find where our nimble stuff is located so we're going to go out to our see users username whatever your username is and you'll see dot nimble here so go ahead and double click on that and bin and you'll see that that is our directory where nim and nimble is located so we're going to go ahead and copy this and we're going to come over to our system properties and we are going to go new and we're going to paste that we're going to hit ok and ok and leave the system properties open we're going to be back here for some godot stuff so don't worry about it so now we're gonna go back to our folder so go to documents go to nim godotnimstub and let's reopen up our command prompt and you need to reopen your command prompt for the new environment variables to take effect unfortunately it's not like linux where you can just go ahead and use it as soon as it's there you have to actually restart your command prompt so now we're going to type nimble install nake and you'll see hey no local packages are found go ahead and download it from the internet yes i would love to and you'll see it's going to go ahead and download naked and install it and for anyone who doesn't know nimble is the package manager for nim so it's like pip for python or for net so it's a really cool package management system that works actually quite well so now that i have naked installed i need to go ahead and make sure i have godot nimble installed erkado nim insult so we're going to say nimble install godot and that's going to go ahead and pull down the godot nymph bindings and install all of that so that way we can have arkado nim bindings and now we need to go ahead and try to build our project so we're going to say nake build and it's going to go ahead and attempt to compile our naked file and you'll see that it fails and the reason why is because to compile our binaries for godot we need to have a good open environment variable remember how i said that we needed to keep that environment variable location open is because we need to have a godot underscore bin environment so let's go ahead and copy this go to our environment variables go ahead and we're going to click new we're going to say godot underscore bin and then we are going to go to browse file and we are going to say downloads and i have godot right here in my download so i'm going to go ahead and click on that open her up and hit ok hit okay and then we need to close our command prompt and then let's go ahead and reopen it because we need to do that for it to take effect and then we can say naked build and you'll see that's going to pop up godot and now it's going to generate all of our bindings and generate our code now this is how you can use the stub project and like i said i haven't really gone into the actual project itself because honestly the stub project does all the work for us so we really don't need to do much more than that so i'm going to go ahead and let this compile and we'll go from there all right so now that it's compiled we can go down into our godot nim stub here and if we go into underscore dlls you will see that we have our nim project compiled so that did all the heavy lifting for us and we actually really don't need to do much else if we don't want to um if we wanted to we could literally just open this up in visual studio code and then just use it so we're going to go ahead and open up godot so that way we can go ahead and see how this built out and then if i go ahead and i go to import because i'm going to import my project i go to my documents and i go to my nim folder godotnimstub and i open up my project here and you'll see hey it needs to be converted that's fine we'll go ahead and convert it and you will see here that we have ourselves our project and you can actually look at the gdns file and the other gdns file that they have and you can see that if i go ahead and i just run their sample project if i click this it lo go ahead and loads a scene which is exactly what we want so i mean that's that's really it from here we can actually come in here so if we open this up in file manager and we and we open up visual studio code you guys can see here let me kind of expand this for you that from here we can come in here and go ahead and go into our src folder and use what he has already built for us right here now you'll notice that i don't have syntax highlighting and that's because we need our nim extension so we can come over to our extensions and type nim and you'll see that we have a bunch of different nim extensions and you usually want to pick whichever one's the most popular which in this case is this one so we'll go ahead and pick this one and then we can go back to our project and open up our nim file right here and you can see that we can actually just come in here and go ahead and modify anything that we want within this file but this is kind of the easy way right you just kind of throw it together and from here we can go ahead and change our code and do what we want to do so if you guys just want to use nim this is a really simple way to do it now i'm going to go ahead and show you guys how to do a hello world program without using the fancy nim bindings and all of that so let's go ahead and do that so the first thing that i'm going to do is i'm going to go out here i'm going to go into my nim folder i'm going to right click and create a new folder and let's just call it nim godot without sample we'll go ahead and double click on that now there are some things that we are going to need here the first folder that we're going to need is we're going to need nim and in the second folder we're going to need for godot to make its project now i'm not going to worry about that right off hand but we are going to need to create that folder now the next thing that we need is we do need our stub we actually need our src folder and we need our nake file and nake cfg file so we're going to go ahead and copy those and we'll go back and then we'll go into nim godot without without uh sample and we'll just paste those in if we go into our src you'll see that we actually have our fps counter in our main panel and our stub nim and we're going to go ahead and delete all of it but the config nims file so once we have everything deleted now we're going to go ahead and open this up with visual studio code so let's type cmd and then we'll type code dot and that's going to open up visual studio code so basically we're going to be making the stub files without actually having the sample project to do it for us now like i said you could just go ahead and delete the two sample nim files and then just go from there but i think it's a lot more fun to kind of figure out how it works less here's just a sample that does it so the first thing that we need to do is we need to look at our config nims file now this is too complicated for me just to cover it in a tutorial so that's why i'm just telling you to copy it over but basically what this does is it says hey when it's mac go ahead and you know use these different uh frameworks right to compile it out if it's android go ahead and do android stuff and if it's windows go ahead and do android compilation stuff so it's basically just doing all of your compiler switches and things like that so that your compiler will compile for the proper framework and like i said this is bit too complicated for this kind of a tutorial so i'm not going to go too in-depth on that one now from here we need to make a config nim file so we'll right click new file and we'll type nim.cfg and what that's going to do is it's going to allow us to config our nim compiler so we're going to say path dollar sign project dir we're going to double dash app colon is lib and then we're gonna dash d colon use real time gc double dash no main as in there's no main entry point and double dash warning and lock level off now what this is is this is the nim confi compiler configuration okay so it allows you to do all sorts of different things so for instance double dash path is your project directory so where it's going to search for all of your compilation files so it's going to search for all your nim files app is telling you if it's going to be a library or an application in this case i have lib so therefore it's going to compile as a lib dash d means i'm defining something okay and i'm defining real use real time gcc or gc and real time gc is your real-time garbage collector so it's saying hey i want to use a garbage collector within my little library here no main means that there is no main entry point and it's basically says hey don't generate a main procedure and then warning tells it not to warn if lock level is off basically it's saying don't worry don't warn anything about lock level just don't worry about it so go ahead and save that and now we need to make our hello world nim file so we're going to right click new and we're going to type helloworld.nim and from here we're going to say import and we're going to go ahead and import godot and we're going to import godot api and then we need to go ahead and extend one of our nodes inside of godot so i'm going to say gd obj hello world of node 2 d and then we're going to go ahead and create a method here so we're going to say method name is going to be ready and we're going to put an asterisk after it as for our memory pointer and then we're going to say is equal to and from here we can actually start coding so we can say self.set process is equal to true what that's going to do is it's going to tell it to process data and now from here we can go ahead and attempt to compile this and see if it even compiles because as of right now we don't know so let's go ahead and open up a terminal and let's say naked build and it will go ahead and attempt to compile it and let's see what it does it probably will fail but we'll try it oh maybe not ah there we go so it says cannot find dot nimble extension inside of specified directory and the reason why is because we are missing our nimble file in that directory so what we need to do is we need to right click new file and call it stub dot nimble and what that's going to do is it's going to allow us to tell nimble what we want to include in our project so first things first you need to type version we'll say is equal to 1.0 0.0 we need to say who's the author and we'll say your name in my case fine point cgi and then description and i'll just leave that empty i don't need a description and my license which in my case is mit because i'm okay with you guys using it now from here we need to say what we actually require for our projects we're going to say require requires quote godot greater than or equal to 0.7 0.21 and it needs to be less than 0.88 now you might be able to get away with the newer version you might just be able to say hey like whatever version of godot just go ahead and pull it down but in my case i've had problems with it in the past if i didn't do it this way so we're going to go ahead and save this and then we're going to try to compile it again and now you see that it says hey hold on a minute all right you're missing your stub file as well your stub nim file so let's go ahead and make that so right click and we'll say stub dot nim and what this is going to be used for is it's going to be used to import in our projects so we're going to say when not defined release colon import seg faults and import and then we need to come down here again and make sure we're out of that when not defined and say import hello world and we need to make sure it matches our nim file so we'll go ahead and just copy this directly and paste that in and that will say that we need to import our specific class that we're looking for now it needs to match this name here it does not necessarily need to match the class here it needs to match your name now in my case i have capital hello capital w world so that's why i made sure that i followed that little convention there so now we'll go ahead and save and try to build i figured out what i did wrong i named this sub not stub so let's let's rename this stub and let's do the same thing here so let's go ahead and rename that stub and let's go ahead and try to build this okay so we got an error here so let's see can i open file godot api i think i need to go ahead and import there we go let me try doing that instead i think it just auto-corrected by accident awesome so now that it's compiled it took us a minute and we had quite a few little falls there but that's okay now that we have it compiling now we just need to get it to print out hello world so from here we should just be able to type we're going to go ahead and attempt to print hello world and let's see if that will take that awesome simple enough so now we have it actually you know creating our stuff so now let's go ahead and make arkado project so we're going to go into sample without nim and we need to go ahead and open up our godot project so let me go ahead and create a godot project so we're going to say new project we're going to go ahead and go to browse go to nim nim without sample create a folder and let's just call it could do a project and set that as our folder let's go ahead and create an edit all right so now we have to go ahead and create our 2d scene so we're going to click on 2d scene we're going to right click on our node we're going to attach our script and we are going to make a native script and we're going to call it hello world all right so now we come over here to our library side we click on here we go to load and we go ahead and load our hello world.tress file so we're going to go ahead and open that and then we are going to save and save our node 2d scene as just test scene and at this point we've saved our script file here so let's go ahead and open it up in visual studio code so i'm going to open up visual studio code and i am going to go over to my godot project and if you haven't already you should probably go over to your nim without sample project folder instead of the nim folder like i did earlier and let's go down to our gdns file which somehow is already open and then we're going to go ahead and do resource underscore name is equal to hello world and then we are going to also say class underscore name is equal to hello world we're going to save that and from here we should be good to go we should be able to hit play and we need to find a main scene so we're going to select our test scene and there we go our output is hello world awesome so that's how you do it manually using nim it's a little bit more complicated than doing it via the self-built plug-in but it does work now something to know with this is any class that you want access outside of godot or outside of your you know internal gdns file right or your you know your internal nim file you need to come into your stub and you need to make sure that you have this import hello world this is where all of your classes that are available to godot goes so you want to make sure that you have that okay and that is only for your entry point so if you have things that are not in your entry points like if you just have you know a utilities class you don't need to have that i mean it's not going to hurt anything if you put it in here but just to let you know you do need that in here outside of that though that's the basics of doing this inside of godot and remember this gives you access to all sorts of information but anyway guys that's really all i have for you guys today so if you like this video go ahead hit that like button hey you know if you dislike this video go and hit that dislike button because i'm here to make content for you guys and let me know what you guys think about nim inside of godot do you think it's worth it you know with all the other bindings we have we have rust and c plus plus and python and things like that do we need nim or do we not need nem you know i do like the syntax of nim it's very python-esque which is nice um and i appreciate that and it does seem to be really fast and i'm gonna be doing a benchmark on this it'll probably be before this video or after this video i'm not sure yet but i'll be doing a benchmark and comparing it against the other programming languages so i guess it'll be interesting to see how it performs compared to the competition but i gotta tell you i do like the syntax that this thing has so let me know what you guys think of the comments below and hey you know if you guys want to yell at me you know you guys can jump on my discord and uh yell at me there link is in the description or of course you're welcome to help me in the comments as always and yeah that's all i have for you guys today so thank you so much again for watching and i will see you all next time thanks [Music] you
Info
Channel: FinePointCGI
Views: 878
Rating: undefined out of 5
Keywords: godot explained, godot tutorial, what is godot, godot getting started, godot beginner tutorial, getting started with godot engine, godot game engine, getting started with godot, godot engine tutorial for beginners, godot engine tutorial 2d, godot engine tutorial 3d, godot getting started 2d, godot getting started 3d, godot review, godot engine tutorial, godot, godot engine, godot creating accounts, godot hashing and salting, godot password salting
Id: WdL-doqxXyo
Channel Id: undefined
Length: 32min 11sec (1931 seconds)
Published: Mon Oct 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.