Help for a complicated code

Godot version 4 (or whatever the newest version is)

so im new here to godot, ive been researching and studying code and only discovered recently godot has a forum (hi) and im making a small multiplayer online game and i need help with a certain aspect, the game is a shooter platformer (think of duck game as an example) and ive yet to find the right codes for the system in place

the game itself consists of 32 characters, and i want player’s eveey 10 seconds to switch from 1 character to another, and i mean more then cosmetically because ive only found options to change outward appearances; I need a code that after 10 seconds, every player changes from 1 character (lets say for example red character with 30 attack damage) to another character (lets say blue character with 35 attack damage) or for a broader example, after 10 seconds a player whos primarily attack based could switch to one thats very defense based, and i want this to happen to all player characters every 10 seconds (sorry if this sounds repetitive, i just want to make it clear i want it to be more then cosmetics) along with this, i want player characters to sustain HP damage (for example a green player takes 25 damage out of 300 HP, after 10 seconds they switch to a purple character and they still are missing 25 damage out of the overall 300 HP, thats what im looking for)

i know this is alot, but ive been struggling with this for weeks, if anyone out there knows any sort of solution please let me know, thank you for going through my long demand lol

TLDR: need help having characters ability/appearance change every 10 seconds and keep HP damage

Quick disclaimer: If you are new to Godot or even game dev in general, doing this complex of a system WITH multiplayer is not a good idea. At all. It will take so much brute forcing its not worth it. Focus on learning more documented and simple mechanics in a one player game.
Now with that out of the way.
Assuming each character has the same type of stats, like health/damage/shield, just store these as variables in the player script. Then have a json file or Singleton which holds a dictionary containing all the characters stats like
{
“health”: 50
“damage”: 30
“shield”: 10
}
Then in the character switching code just look up the new characters stats and change the variables.
In terms of multiplayer, just send this change over an rpc with the id like “blue-char” and then run the same variable-switching code on the other clients.
Good luck!

1 Like

You could create a Resource script with all the parameters you want to change.

extends Resource
class_name CharacterAttributes

@export var texture: Texture2D
@export var attack_damage: float

Then your swapping character can use an Array of these resources to progress through each character. Using a Timer node to keep pace.

@export var characters: Array[CharacterAttributes]
var character_progress: int = 0

func _on_timer_timeout() -> void:
    # increment to next character index
    character_progress += 1
    # wrap back to 0 if over maximum
    character_progress %= characters.size()
    var next_character := characters[character_progress]

    # assuming you are using a Sprite2D child
    $Sprite2D.texture = next_character.texture
    self.attack_damage = next_character.attack_damage
4 Likes

That’s a solid solution. Probably cleaner than mine, lol.

If you are also new to programming and computer science I would suggest taking a little time to learn it as it will help you in making complex games. Learn some design patters and principals like KISS (Keep It Simple Stupid), SOLID (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion), DRY (Dont Repeat Yourself), SOC (Separation of Concerns) this is just a few. Having a good understanding of things like this will help you immensely. You dont have to know everything but a good background will help you more easily handle complex code as these things all give you ways to make complex code easier to deal with.