Iron Village ​Diary #1 – GDScript & C# in Godot

For this week, I wanted to start the whole thing off with the captivating topic of… programming languages? Ok, not exactly gripping stuff, but bear with me.

So Iron Village is being developed in Godot, a free and open source game engine. It actually started in Unity, but then the whole pricing fiasco happened about a day or two into actual development, so I went ahead and made the switch. One of the goals of the Iron Village project is a learning experience, so it wasn’t too much of a stretch to extend that to learning a new engine.

As those of you with knowledge of the game dev space may know, you can use two different languages with Godot: GDScript and C#. C# is a pretty common language, it’s the main language used when developing in Unity (originally one of three, but when they focused on just one language they picked C#), and it’s used in some programming for Windows as well. (I’m honestly not that familiar with that side of things.)

GDScript is a really interesting language though. It’s specifically designed as part of Godot, and syntactically it looks just like Python, with some minor improvements that regular Python ought to have. You can tell it was the main language the engine was designed around, and the API reference documentation is all in GDScript.

So at the start, I decided to try out GDScript for Iron Village. I like Python as a language, the main thing I’ve used it for in the past few years is automating some of the grunt work with setting up mods for Paradox games, or duplicating files for building variations in Cities: Skylines asset creation. This would definitely be the biggest project I’ve done with anything Pythonesque though, and the last time I had done so for a game project was more than a decade ago in college using Pygame.

It’s been working fine so far, but curiosity got the better of me and I wanted to see what C# in Godot was like. It turned out that the languages are supposed to be interoperable with each other (more on that later). So I decided that I would either make one new script in C#, or convert an already existing class without too many dependencies. Accessing C# code from GDScript is supposed to be easier than the other way around, so I converted something that was relied upon by everything, but relief upon nothing else: the GameResources class. This is a singleton object I made for storing and checking resources, things like gold, wood, and crops.

This actually went pretty well. There was one snag, accessing C# enums from GDScript, so I did have to temporarily hard code some numbers and come up with a better fix later. Except that triggered part of my brain to go, why not convert a few more small things?

Lol.

It’s still early enough in the project that it’s technically feasible (although arguably a waste of a lot of time), but I’m about two thirds of the way through converting everything to C# now.

Ultimately, I missed strongly-typed languages too much. Having to declare and keep track of exactly what is in each variable can be a decent amount of overhead, but the benefits (especially with IDE features like refactoring and right click -> go to definition) are so good. Ultimately, I think it makes you write better code, since a lot of mistakes that would cause runtime errors in GDScript get caught by the compiler in C# instead. It was still nice to use GDScript, but I’ve made the choice that works best for this project, IMO.

TL;DR: I’m a dumbass who started switching languages part-way through development.

P.S. I’ve made a Discord server, because that’s a thing I guess.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *