I am curently creating my own Pokemon like RPG and to do that, i have followed a tutorial series by the Youtuber Coding Quest. He explained everything clearly, but he left out one important aspect. He did not explain how to make the opponent choose an attack at random from his repertoire to attack. And now I just don’t know how to program this into my game. I’ve already written to the Youtuber, but the tutorial series and the video in which my problem begins are already a year old, so I don’t think he’ll reply to my message.
I’m just a beginner in coding (and I’m not very good at it) This is also my first message in the forum and I’m not sure if I should just put all the code from the tutorial in the message (because it’s really a lot of code) or if it’s enough if someone just shows me the flow of turn based combat
I apologize for the bad grammar and spelling mistakes if there are any but english is not my native language.
In the battle scene I have a node called Player and one called Enemy which have the respective monsters on each side as children. The players turn is determined in the UI node. The turn of the enemy monster in the battle scene itself.
Here is the code from the battle scene:
extends CanvasLayer
var escargel = preload("res://Esentia Battle/Escargel.tscn")
var selected = 0
# Called when the node enters the scene tree for the first time.
func _ready():
var montemp = escargel.instantiate()
$Enemy.add_child(montemp)
$Enemy.scale.x = -1
$UI/Menu/GridContainer/Angriff.grab_focus()
for i in Game.selectedEsentia:
var monTemp = Game.selectedEsentia[i]["Scene"].instantiate()
monTemp.name = Game.selectedEsentia[i]["Name"]
monTemp.hide()
$Player.add_child(monTemp)
$Player.get_child(0).show()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_item_pressed():
pass # Replace with function body.
func MonsterTurn():
$UI/Menu.hide()
$UI/Switch.hide()
$UI/Fight.hide()
var damage = randi_range(5,8)
await get_tree().create_timer(2).timeout
if $Enemy.get_child(0).Health <= 0:
Game.addExp(10)
$"../UI/AnimationPlayer".play("TransIn")
await get_tree().create_timer(1.5).timeout
$"../Player/AnimatedSprite2D".visible = true
get_tree().paused = false
queue_free()
$"../UI/AnimationPlayer".play("TransOut")
$Player.get_child(selected).hit(": Schleim", damage)#HERE IS THE PROBLEM.
$Action.text = "(Gegner) " + $Enemy.get_child(0).name + " setzt eine Attacke ein! "
Game.selectedEsentia[0]["Health"] -= damage
await get_tree().create_timer(2).timeout
$UI/Menu/GridContainer/Angriff.grab_focus()
$UI/Menu.show()
Everything works perfectly, I just don’t know how to get the opponent to randomly select an attack from his repertoire at line 46 and use it.
I hope it is roughly understandable what I mean. I am not really good at explaining.
Then you can just reference the dictionary as follows:
var entity_attacks = Game.dataBaseEsentia[0]["Attacks"]
Make sure that you replace the “0” with the corresponding entity index.
And just a little tip. You are storing a lot of data in a dictionary. Godot has a nice way of dealing with this called “Resource”. You can look up some tutorials on custom resources, this makes creating all this data way easier and also easier to handle