Code architecture questions for a simple game

Godot Version

4.2.1

Question

Hi everyone,

I have a question about the general node hierarchy and the best ways to connect the various parts of my game.

Background: I am new to Godot and game design generally, but know a bit about coding. I wanted to make a simple text based game to get used to the fundamentals without worrying about graphics. A sort of resource management game where the player manages a medieval town.

I think the four main branches of my game should be (I’ve coded a lot of this already)

  • Output - Mostly writing text to the screen
  • Input - Handling the user’s input
  • Data - Storing game data/updating/saving/etc
  • MenuManager - The various ‘menus’ the user interacts with to buy/sell/check the status of things/etc. These menus would contain my game logic.

My question is: what is the best way to connect these four parts in terms of their hierarchy and how they should communicate?

For example, the Menu system needs to be able receive strings from Input, and send strings to Output, and read and write the data. Should all that happen with signals to keep them loosely connected? That seems like a lot of signals…

Or should I have a root node that handles the communication between the four branches? That seems like a lot of up-down-up-down communication that will be hard to set up…

Should the Menus be a child of Input, to have those strings feed down easily? Should Data be a child of the Menus since they interact a lot?
Should anything be global?

I’m just wondering if there are some good practices I should follow here. This seems like a problem that would crop up in one way or another in most games. Do you have any tips or tricks or things to avoid. (BTW: I do know about the concept of ‘reference down, signal up’.)

Thanks for your help!

1 Like

You have everything in a single scene? No scene switching?

I tried your approach in the beginning when I didn’t have a lot of experience. Sure, you can learn about enhiritence and composition, signal managing and many standards. I found that this became quite messy rather quickly. Maybe this approach wasn’t suitable for my game.

Instead, I started using autoloads and that made it much easier. Now I can centralize processing of data and events that’s accessible from anywhere. I made a signal broker that can connect anything to anything.

I think you’re on the right track for your use case, but I do want to point out that you are ultimately in charge and can use any standard that works for you. Maybe you can bundle some signals into one. For example, if your menu has 6 options, instead of creating 6 signals, create one signal and pass trough the item that was clicked.