Asking for some advice while I plan how I'm going to implement my simple 4x game.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By skonar2


I’m not a very advanced coder, so, keep that in mind. But I do like planning what I’m going to do ahead of time, so…

I’m planning a very simple 4x game, and I think there’s going to be a lot of global data to pass between scenes and screens. Currently I have two screens - space screen, to show planets and stars and where the units are on those planets and stars, and battle screen, to do battles.

I COULD implement all of this in a single scene with dialogue menus or something, but I’m trying to code this in such a way it helps me understand what I’ll need to do for more complex versions. Right now the battle screen is just a fancy dice rolling spread sheet, but, one day maybe it’ll be a turn based hex grid thing, so, it’s a separate scene.

My units are really simple at this stage, with just one kind of unit - a battlepod - but I want to implement them as individual objects so later I can do things like give each unit a history, unique loadouts, xp points, all that.

So, firstly:

I’m not sure if I should be implementing my battlepod units as a node that spawns on the space screen, then when I switch to the battle screen I somehow save the space screen data (where the planets are, what units are on them), pass the units that are in battle to the battle screen, do the battle, then re-load the space screen data, repopulate the space screen, and modify the space screen with the battle results…

OR, if I should be implementing my battlepod units and space screen data as some kind of global object - like the autoloads - which persist no matter what scene I have loaded, and then in each scene have some kind of code to create new nodes to show the relevant sprites in the right places.

The other big issue is I’m not sure how to handle displaying the units on the space screen. My plan is to have an icon appearing next to each planet, representing a unit, with a number beside it to show how many units are on the planet, but I’m not sure how best to count them. I was thinking about some kind of function to make the battlepod units ‘report’ their location to the planet, and then have the planet count the number of reports? Would that work, or is there something more elegant I could do?

Can anyone offer opinions on all this? Advice? Or maybe tell me if there’s a better approach I’m missing?

:bust_in_silhouette: Reply From: DDoop

I think that you might be overthinking in advance. For instance, you’re worrying about what will happen to the data in the space screen while you’re displaying the battle screen to the user. From my knowledge of Godot, this is fairly trivial to accomplish: nodes are perfectly happy to exist outside of the scene tree (where they cannot be seen) and still hold the same data they held when they were visible to the player. This is why when you instantiate a node with .new(), you also need to add it to the scene tree somewhere with .add_child(new_node) on a node that’s already in the scene tree.

In general, I think autoloads should be avoided except with good cause.

Regarding determining the relative size of military forces in a given location: you’ll want to do work “lazily” as much as possible, in other words, only when necessary. Your current solution involves planets requesting data from military units at an arbitrary time interval. How frequently would the planets ask for that data? What if they ask at a bad time? It might be better instead to couple the logic that moves units on/off planets with the logic that tracks how many units are on a planet. For instance, when you move a unit to a planet, the number will increment, and when you move a unit off, it will decrease. You’d of course also need to increment the counter if a unit was produced or lost to combat, attrition, or however you plan on modeling casualties.

My biggest piece of advice to you is to try all of these things :slight_smile: You usually can never really know which will work and which won’t until you put some work into spinning them up. 4X games have a huge scope, so at the very least you will always have some problem to pick and pull at.

That is some very helpful advice. Thank you!

Also, clearly I misunderstood something about the scene tree. I thought that once a node was removed from it (by switching scenes, for instance) it was just… gone? Clearly I misunderstood something there and need to read up more about scene switching.

If I understand you correctly (and so I have a link to come back to this easily), you’re talking about using method 3 - remove the existing node from the tree - from this page? ( Change scenes manually — Godot Engine (stable) documentation in English )

skonar2 | 2020-12-14 12:31

That link is very handy, yeah I mean method 3.

DDoop | 2020-12-14 15:23