0 votes

hi, this is my first question im very beginner to godot, Im making a simple turn based game similar to hearbeast tutorial.
On extending his tutorial, Now my enemy does only damage in his turn
But i want him to pick random move in his turn such as healing...
This is my damage code in enemy scene :

func deal_damage():
damage = rng.randi_range(4,10)
BattleUnits.PlayerStats.hp -= damage

Should i create func healhp like that,Even after creating function healphp how can i make my enemy to pick any one move in his turn
This is my attack code in enemy scene

func attack() -> void:
yield(get_tree().create_timer(0.4), "timeout")
yield(animationPlayer, "animation_finished")

This is my code in battle scene

func start_enemy_turn():
var enemy = BattleUnits.Enemy
if enemy != null and not enemy.is_queued_for_deletion():
    yield(enemy, "end_turn")

Is using function is a right way OR
Is there any other better solution to determine enemy to pick a random move in his turn... Please I need help

Godot version 3.2.3
in Engine by (56 points)

1 Answer

+2 votes
Best answer

You could do something like this (inside enemy) :
const moves := ["heal", "attack", "attack", "defend"]
var next_moves := []
func play():
. if next_moves.empty(): // Refill on moves
. . next_moves = moves.duplicate()
. . next_moves.shuffle()
. var action: String= next_moves.pop_front()
. call(action) //Call a function by name
func heal():
. pass
func attack():
. pass
func defend():
. pass

This allows you to easily change what the enemy can do as it goes, by adding or removing elements from moves.

by (2,688 points)
selected by

works very well

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.