Sanity Check, is My Code Okay?

Howdy! This is my first time making a game without a tutorial and yesterday I spent the entire day trying to work out the basic flow of my game, but I kept overthinking it. I am just wondering if what I came up with is a reasonable and efficient way to do what I am trying to do.

The game idea is basically Lara Croft GO and Hitman GO, but it’ll be 2-D. If you aren’t aware, it’s a puzzle game where you need to make it to the end gate, but enemies are in your path. The only way to get past them is to attack them from behind, get them to kill each other, or kill them with the environment. When the player makes their one movement, the enemies will respond by doing nothing, or if the player is in their line of sight, they’ll move/attack. I would also like environmental variables like flowing water, rolling boulders, or traps to move next. Then it loops back to the player’s turn if they’re alive.

extends Node

var my_turn : bool = true

func _process(delta):
	if Input.is_action_just_pressed("ui_right") and my_turn:

func player_turn():
	print("I took my turn")
	my_turn = false

func turn_cycle(): #This outlines everything else that gets to happen after the player has made their move
	#after everything has gone, it is now the player's turn again
	my_turn = true

func enemy_turn():
	print("enemy took their turn")

func environment_turn():
	print("environment did their thing")

I’m sad to say that this took over 8 hours to come up with. I started small and simple, but when I Googled my problem, I was convinced I needed a TurnQueue. I made an array and put the children in it, then I got stuck when I found out yeild was deprecated, then I tried using await, then I tried signals. Once I remembered that the order will never changed, I scrapped the array and TurnQueue idea. Moral of the story is KISS.


I think you’re on the right path.

Is this code in the player’s script? You probably don’t want the player script managing the turn order. I would make some kind of “game manager” script that handles the turn order, and just have the player and enemies check in with that script.

You may find yourself still wanting a queue (e.g. if certain enemies need to move before others), but you can always add that on top of this later.

But yeah, in general, the simplest solution is usually the best.

1 Like

Lol, I put player movement in the main script by accident, yeah. You live and you learn. At first it was only to see if the whole function worked, but my brain never caught up.

You could still mimic a yield by making your own class that returns the next element in a queue or array. If I think about yield being replaced by await it’s still almost the same thing but it can be unhelpful if using inside the process thread because it doesn’t actually block. You may need a chain of awaits in your script to make a coroutine. Many think yield is a bad practice since it can easily lead to issues if used improperly.

1 Like