I'm trying to make an rpg game with turn-based combat. My code needed to have a slight randomness to the damage, and I'm getting this error: Invalid operands 'int' and 'Object' in operator '-'. e stands for enemy in this code
func _on_FIGHT_pressed(): #is connected to a button
var damage = RandomNumberGenerator.new()
damage.randomize()
damage.randi_range(pattacks[0][1], pattacks[0][2]) #uses your-only-attacks's min and max damage
ehp -= damage #subtracts your damage from the enemy's hp
Before I was using the pseudo-random rand_range bult in method, but then you'd press a button and the same damage would come out the second time you get into a fight. I am in fact using godot 3.5 release
Notice that damage
is a RandomNumberGenerator
. It says so here:
var damage = RandomNumberGenerator.new()
You probably want the result of randi_range
(it returns):
ehp -= damage.randi_range(pattacks[0][1], pattacks[0][2])