My new goals with coding a turn based RPG

My goal with coding this RPG is to achieve the following:

  • Neat and organized code achieved by dividing the code into multiple “chunks” (just scripts attached to base Nodes), This way I could avoid the dreaded 300+ lines scripts and also abstract the complexity and encapsulate the logic, Say have a “AttackingManager” Node and a “TakeDamage” Node as children of the parent “Battler” Node

  • Using classes to organize long data, There will be an “Action” class that includes a reference to the battler performing the action + the type of action + action data (attack damage, spell type) + action target (self, enemy, all allies, all enemies), This way we can avoid functions with like 5 arguments.

  • Using inheritance, To simplify logic I’ll make a base “Battler” class, Then have 2 child classes being the “AllyBattler” and the “EnemyBattler”, Each class will override the parent methods like “decide action” and “defeated” in their own way.

  • Straight and easy to track code, I really don’t want any Spaghetti code, I’ll try to make it so that a code sequence is in on place, So no jumping around objects to track errors !

  • Using functions to reduce repeated code, If i find myself using a line of code repeatedly then making a little static function to run that code should reduce the risk of error and simplify code !

  • Using an array to handle battler actions, I think that having each battler “decide an action” and then appending that action in an array of “Actions” in the “BattleManager” scene would be a neat way of coding the turn system, when all battlers have appended their actions we’ll first sort the actions based on the battlers speed stat, Then we’ll iterate over the array and perform each action and remove it once we’re done with it.

Anyway that’s it, Tell me if you have any criticism !

Is this text ai generated?
Fine I guess but, why not actually write out what you want to do yourself.

A lot of this seems off, but especially the following:

Quite typical of chatgpt to say these things.

In gdscript you cannot even make a static function.
In c# you can but you dont seem to use that.

For actual criticism:

Use a resource for this, not a class.

To properly map out the full mechanics and functionality of something like an RPG on paper is a tough task, requiring all your requirements are fully understood and your vision is clear and detailed about the gameplay and outcomes. Something like that, IMHO, only a very experienced and senior programmer can do well, and even then that task is a monumental one.

Your aims like ‘no spaghetti code’ etc are all true for anything you code. You can always refactor and tidy the code later. In fact, decisions like using inheritance should not be take lightly. Composition verses inheritance is an age old choice faced by almost everyone, with no ‘correct’ answer.

My advice would be to start building your game. It sounds like you are in a prototyping stage, where you can investigate how the gameplay feels, come up with new ideas as you develop, and don’t worry about dirty, messy, inefficient code etc until you are happy with your prototyping. At this stage you will be rewriting and exploring, creating scenes to investigate a single mechanic etc. This is a fun part, enjoy it, explore your game. Get people to have a go, even if it is a single scene. Use placeholder art for instance, don’t get bogged down in any single detail.

Once you are happy with your aims and intentions, many people then start again, now knowing fully the mechanics they intend to employ and build. This is your production build, where now you think, that mechanic I cut and pasted into 10 enemies, how can I best create that properly? Or, the game difficulty, that I hard coded into my levels, how can I best store and access that data?

Even then, you may find yourself refactoring still, rewriting parts again when an unforeseen complication arises. You will never be able to start a new project or game idea and write production quality code off the bat. And even if you could, your game would suffer because you never played with it, exploring the game concepts and focussing on the fun parts. So forget all this 'I don’t want functions with more than five arguments. If it needs ten arguments that give it ten arguments. Or the scripts with 300 lines in it, why not? Good code is not short code, good code is maintainable, reliable and easy to follow. Short does not come into it.

Good luck, get coding, just jump in.

3 Likes

Just to note this is what my AI thought you should do:

When planning to code an RPG, employ these key tactics:

  1. Start with a solid foundation:

    • Define your game’s core concept, including genre, theme, and unique selling points[1][2].
    • Create a game design document (GDD) outlining essential aspects like story, characters, gameplay mechanics, and levels[1].
  2. Focus on essential elements:

    • Craft a compelling narrative that drives player engagement[2].
    • Design characters with depth and unique abilities[2].
    • Develop balanced combat and exploration systems[2].
  3. Plan your development process:

    • Break down the project into manageable sprints, focusing on small, achievable tasks[1].
    • Set clear milestones to track progress and keep the project on schedule[1].
  4. Prioritize gameplay mechanics:

    • Implement the most basic gameplay features first, ensuring they are fun on their own[3].
    • Gradually combine basic features into more complex gameplay elements[3].
    • Regularly playtest and iterate on these mechanics[2].
  5. Design flexible systems:

    • Create a TurnManager class to handle turn-based gameplay, if applicable[6].
    • Develop a generic UI system that can adapt to different character needs[6].
  6. Build incrementally:

    • Start with a vertical slice or first level, focusing on core features[3].
    • Expand and refine the game gradually, adding content and complexity over time[3].
  7. Optimize for a small team:

    • Focus on your core gameplay loop[5].
    • Simplify mechanics and systems to make development more manageable[5].
  8. Incorporate regular testing and feedback:

    • Conduct frequent playtests to identify and fix bugs[2].
    • Gather player feedback to refine gameplay mechanics and balance[2].

By employing these tactics, you can create a structured approach to coding your RPG, ensuring a more efficient and successful development process.

1 Like

I swear to god I wrote all this myself :sob: I guess my writing style is a bit robotic lol.

Anyway you can totally write static functions and variables in GDscript ? You can about them here.

And yeah I agree resources are very helpful but classes would be better in my situation I feel.

2 Likes

Thank you so much for this advice ! Genuinely very helpful

1 Like

Thank you ! Also this is your AI ?!

1 Like

Lol, I like to think of it as mine!

Actually it is Perplexity, which is very good at Godot code too.

https://www.perplexity.ai/

PS Strangely the quality of the answers I get is better at night than during the day. I can only imagine it is because they have to share resources more when they are busy? Who knows but it is noticeable.

It just looked like that, nothing wrong with your writing style.
As for the static functions, never have I seen them before, but if the docs says so, then I am wrong there (I mainly use c# so, I am not that deep into gdscript).

I still do think that using resources for this is better.

Because in my mind classes should perform logic, while resources should just hold data.
Your action resource could then be like:

extends Resource

enum action_type {TYPE_ONE, TYPE_TWO }
enum target_type {SELF, ENEMY, ALLIES, ALL}
enum spell_type {WATER, FIRE, ELECTRIC}

@export var type: action_type
@export var targets : target_type
@export var spell: spell_type 
@export var damage: int
@export var attack_speed: float

Then just make resources like this and change some values, to create different attacks. Then in your attacking script, reference these variables.

2 Likes

This is very intresting…I might do this !