This function is meant to return the kind of attack used based on the num variable. So for example, passing in 1 would return the attack1 scene. Is there a way of condensing this code further? I have similar if and elif stacks in my code and its cluttering up my code a lot.
func attack(num: int):
var attackUsed
attackUsed = "res://scenes/attacks/%s.tscn" % str(num)
assuming your playerStast.attack1 is exactly 1==1, and playerStats.attack2 is 2==2
problem is it’s not, so you cant
there’s other choice too, using match:
func attack(num: int):
var attackUsed
match num:
1:
attackUsed = "res://scenes/attacks/%s.tscn" % playerStats.attack1 # playerStats.attack1 is a string
2:
attackUsed = "res://scenes/attacks/%s.tscn" % playerStats.attack2
3:
attackUsed = "res://scenes/attacks/%s.tscn" % playerStats.attack3
other things you can do is to actually store the attack num and playerStats.attack string into key and value of a DIctionary:
and actually use the Dictionary to link between num used so calling the respective playerStats.attack