Creating a mana distribution systeme

Godot Version

Replace this line with your Godot version

Question

hello guys, i was wondering if someone know how to create a systeme where the player and the opponent gain +X mana at each turn (exemple: turn 1 each player gain +1 mana, turn 2 each player gain +2 mana cap at 20 mana) its for a card game i’m creating and i really don’t know how to code this function

I recommend doing some basic tutorials first from the documentation to understand the basic functionality of the engine, and perhaps some basic coding concepts as well.

2 Likes

yeah, i already look to it but i can’t figure how to make it functionnal, like i don’t know how to program it so if you have any idea i take it

Do you already have a way to pass the turn to the opponent?

yeah i do have it but it just i want a system who make each player (or the player and the ai because i don’t have setup multiplayer yet) to have each turn +x mana (like i said for exemple : turn 1 +1 mana each player, turn 2 +2 mana etc, and each end turn it reset the mana to the curent turn)

like in hearstone or plant vs zombie heroes for the one who know this game

One solution could be to have a separate node with a separate script.

Create a function like add_mana(caller). in ready, connect it to the signal mentioned below.

And whenever you switch to another player, you emit a signal from that player. Include self as an argument in the signal, if emitted from the same script.

The add mana function could be very simple. Like check turn count and pick amount of mana to add based on a table. Then add that amount with something like caller.mana += amount

Not a flawless solution but a possible one!

So, there’s a operator in programming += It means take the value on the left, add the value on the right to it, and then make that the new value for the value on the left.

So if you want to increase it every round it might look something like this:

#player.gd
extends Node

var starting_mana: int = 1
var current_mana: int

func new_round() -> void:
	starting_mana += 1
	clampi(starting_mana, 1, 20) # The minimum it can be is 1, and maximum is 20.
	current_mana = starting_mana

This will allow you to remove mana from current_mana during the round, but reset it to the new amount every subsequent round.

1 Like