Building games with Godot Engine

Thanks for telling me about this thread, Schmidt! I’ve been using Godot for almost 2 years, now, streaming gamedev nearly every weeknight. I’m happy to try to answer any questions. I mostly deal with 3D stuff. Fist of the Forgotten is the project I’m currently working on.

Welcome @jitspoe! Have you been following the Godot 4.0 devs and their 3D/Vulkan work? Looks like there are some great optimizations coming soon.

Also, I see you were at Bosskey… are you in Raleigh?

I haven’t really been keeping up with the Vulkan stuff. My game currently runs at like 600-1000fps on my not-so-current machine, so I’m not too concerned about the performance improvements. :D My biggest complaint right now is the physics. Godot uses Bullet under the hood, which is very inaccurate and unpredictable. Ok for FX, but not good for gameplay. I’ll likely have to write my own collision detection for the character to make the movement really solid.

I’m near Raleigh, yeah.

Nice. There are 4-5 other qt3’ers in the Raleigh area. In the days before the apocalypse, we were starting to get together for a beer and dinner more frequently; or at least lunch at Mami Noras.

I work with (at least) one of your former Bosskey colleagues, maybe more. Once the virus is no longer a threat, I’d be down for a Raleigh Godot meetup, if you’re interested.

Here’s a fun-looking little game that somebody posted on Reddit – claiming to have completed it in 3 weeks.

For you Godot experts out there, I’m getting an error that I can’t figure out when running the below function code within Godot. The parse error I get is: Parser Error: Variable “cell” already defined in the scope. So I know it’s a scope error of some kind but I can’t figure out why. The variable is defined and given a value within the function (var cell = yield(GameData.game, ‘map_clicked’)) and is then referenced below that in a for loop(for cell in path:) which generates the error related to the first line. Since the variable is defined within the function and used within the function, why is this a problem? How do I fix this? Note that I’m using Godot 3.2.2.

func throw(slot):
	# Check if item can be thrown
	if self.throw_range <= 0:
		GameData.broadcast("You cannot throw that!")
		return
	if object_owner.has_node("Weapon"):
		if self.equipped == true:
			GameData.broadcast('Unequip a weapon before throwing it')
			return
	if object_owner.has_node("Torch"):
			GameData.broadcast('You cannot throw away your torch, your life depends in it!')
			return
	if object_owner.has_node("Armour"):
		if self.equipped == true:
			GameData.broadcast('Unequip armour before throwing it')
			return
	GameData.broadcast("Which direction? Click the map to confirm, RMB to cancel")
	# Place mouse pointer on game map
	get_viewport().warp_mouse(get_viewport().get_rect().size/2.0)
	# Restrict mouse pointer until object has been thrown or cancelled
	GameData.in_use = true
	var cell = yield(GameData.game, 'map_clicked')
	if cell == null:
		GameData.broadcast("action cancelled")
		GameData.in_use = false
		return
	else:
		GameData.broadcast("You throw " + object_owner.get_display_name())
		drop()
		var path = FOVGen.get_line(GameData.player.get_map_position(), cell)
		if not path.empty():
			var tpath = []
			for cell in path:
				var actor = GameData.map.get_actor_in_cell(cell)
				if actor and actor != GameData.player:
					tpath.append(cell)
					break
				elif GameData.map.is_wall(cell):
					break
				else:
					tpath.append(cell)
			if tpath.size() > self.throw_range+1:
				tpath.resize(self.throw_range+1)
			self.throw_path = tpath
			var done = yield(self, 'landed')
			var target_cell = object_owner.get_map_position()
			var target = GameData.map.get_actor_in_cell(target_cell)
			if target and target != GameData.player:
				if self.throw_damage > 0:
					target.fighter.take_damage(object_owner.get_display_name(), self.throw_damage)
		GameData.player.emit_signal('object_acted')
		GameData.in_use = false

So this isn’t a Godot-specific issue, but Godot’s compiler is pointing it out to you.

When you do for x in y:, you create x as a ephemeral variable that only exists inside of the for loop. You can call x whatever you want for the purposes of that loop. The x variable is created anew and assigned the next value in the iterable y for each pass of the loop.

What’s happening is that the for loop is trying to create an ephemeral cell but the compiler is disallowing it because cell already exists as a variable. Change the name of cell in the for loop to something else. You can call is just c or dingleberry or whatever you want.

(Warning: I did not examine the function in whole or the rest of the logic so fixing that issue might not fix the entire problem, but that’s what Godot is complaining about in that instance.)

Aha, thanks. This is someones example project code that I’m using to learn Godot so it wasn’t great that I ran into this when I tried to run it. There was also another parse error but I was able to figure out and fix that one.

Edit: It turns out that this project was built under Godot 2 and it doesn’t work under Godot 3. Back to the drawing board.

I did a quick read through of the Godot scripting language doc and was then able to fix all the parse errors in the project. Now I have a working, totally open source code example of a small, simple roguelike game built with Godot that I can revise and add onto as desired. Pretty dang cool.

Nice!

Though I thought this project was already ported to 3.1, if you select the correct branch?

Still, a valuable learning experience I am sure! Keen to see what you end up doing with it. :)

Yeah, that’s the one I downloaded (I have 3.2 so I don’t know if that affects anything as far as the errors). The original game creator didn’t want to mess with the port from 2.1 but another guy volunteered to do it for him. He fixed just about everything but a few minor errors that was keeping it from running from inside the editor. So, I fixed those. You can run it from outside the editor fine though. The lighting was kind of weird so I set it to GLES2 from GLES3 and that seems to have improved it. I’m going to mess around with the code some to see what I can do with it. Unlike a lot of these little roguelike projects, this one seems pretty polished visually. The game part is really very basic but that’s what I want in order to learn all this stuff.

Good work @Coldsteel! That’s awesome. Keep us posted with what you build.

Trying to throw an object from my inventory in the game wasn’t working and causing an error to pop up saying the get_rect() function doesn’t exist as a Viewport method. After some research I found out that they dropped that in Godot 3. A few code changes and now it’s working again. I’m sure I’ll run into more little stuff like that as I go thought the project. At least I’ve found out that Godot debug is pretty darn nice.

I hope @Clay or someone else here can help on a Godot issue I’m having.

When trying to open a Tileset scene for the above Roguelike project in the 3.2.2 editor I get the following error:

scene/resources/resource_format_text.cpp:528 - res://tilesets/Dungeon_edit.tscn:120

  • Parse Error: Unexpected identifier: ‘Image’.
    Failed to load resource ‘res://tilesets/Dungeon_edit.tscn’.
    Failed loading resource: res://tilesets/Dungeon_edit.tscn.

Researching the issue, I found a bug report on the Godot site related to converting projects from Godot 2 to 3 ( Extra issues converting from 2.1.5 to 3.0.6):

  • My GUI theme contained embedded ImageTextures of the default theme, which Godot 2 inserted itself in the past. I didn’t realize that, but the unexpected part is these images were completely dropped after conversion, preventing the theme from being opened at all in the editor:
ERROR: poll: res://menus/theme.tres:45 - Parse Error: Unexpected identifier: 'Image'.
   At: scene/resources/scene_format_text.cpp:523
ERROR: load: Condition ' err != OK ' is true. returned: RES()
   At: core/io/resource_loader.cpp:149
ERROR: Failed loading resource: res://menus/theme.tres
   At: core/io/resource_loader.cpp:186
ERROR: load_resource: Condition ' !res.is_valid() ' is true. returned: ERR_CANT_OPEN
   At: editor/editor_node.cpp:557
  • After getting rid of those embedded images (which didn’t break the original theme in Godot 2), I was able to open the theme in Godot 3 but I noticed it got rendering inconsistencies:

Okay, from that I can see this is a Godot issue and since the bug report was from back in 2018, it doesn’t look to be fixed anytime soon. The guy said he was able to open his scene after getting rid of the embedded images. How do I do that if I can’t open the scene file in the editor to fix this?

Converting from Godot 2 to Godot 3 can be problematic. Have you tried downloading the latest version of Godot 2 and opening the resource in question, removing embedded images, and then saving it and using that in Godot 3?

I thought of that but was hoping to avoid it in case it reintroduced other conversion issues back in. I guess I’ll give it a whirl but at this point I’m thinking I may just put down the project for now. I’ve run into other conversion issues as well that I’m having a hard time resolving. Maybe I’ll come back to it once I’ve actually learned Godot since then I might have a better idea of how to deal with it. I’m going though their latest Godot documentation and doing the examples and tutorials currently. Once issue I’m having is that the vast majority of the user made tutorials out there are for Godot 2. There isn’t that much out there for Godot 3 yet.

If you’re up to paying a few bucks for a good tutorial series, this one on Udemy is really good. From there, you can use Kenney.nl assets as a jumping off point for working on your own small games.

The other thing is that most Godot 2 tutorials are going to work just fine in Godot 3. There were some large changes, for sure, but gameplay implementation and resource management are mostly the same.

I can confirm - its pretty good. Especially if you have some prior programming knowledge I am sure you will blaze right through it.

So - A Godot / General learning programming question. I have completed two projects now in the GODOT training mentioned above. A Word game, and a 2D sidescroller game.

There was…well, quite a few things I never really did understand how worked - at least not completely.

The next project is, as far as I can tell, a 3D stealth game, with higher complexity I am sure.

Would you recommend just powering through, learning as much as you can, and THEN trying out stuff for yourself, or should I try out stuff now, already?
I am pretty sure my first project is going to be a character generator - either for a real Pen&Paper rpg, or a fictious one, just to get to understand how it works.

Anyways - any input would be appreciated!

I recommend powering through, then maybe going back and doing the first project or two again to see if you understand more… You can also start your own project at the same time and refer back to the projects from the class, as needed, when you run into a situation where you need help or to remember how to do something.

I find that the hardest thing is hopping from a course like that to your own project that doesn’t have anybody guiding you. Questions like “where do I start?” can be a real motivation killer. What you get from the course is a few examples of how to start, so fall back on them for starting your own, etc.