Invalid operands "String" and "Nil" operator in "+" on a skill bar switch?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Erraco

Hi i have an issue while i was following a video tutorial that shows how to make a skill bar switch.
I get the error Invalid Operands ‘Int’ and ‘String’ in operator ‘+’ every time i run the game,
this is the line of code that prompts the error
var skill_texture = load(“res://graficos/Skills/” + skill_name + “.png”)
help?
(graficos is my assets folder)
heres the code
i tried to command the skill_name to be converted to a string for this purpose using load(“res://graficos/Skills/” + str(skill_name) + “.png”

but then i got the error invalid type in Vector2 constructor. cannot convert argument 1 from nil to float.

I really dont know how to proceed, im still a beginner
extends RigidBody2D

var axe_speed 
var life_time = 3
var damage 
var skill_name 


#var fire_direction
#func _init(_skill_name):
# skill_name = _skill_name


func _ready():
 match skill_name:
  "Spear":
   damage = 40
   axe_speed = 200
  "Axe":
   damage = 30
   axe_speed = 400
 var skill_texture = load("res://graficos/Skills/" + skill_name +  ".png")
 get_node("Projectile").set_texture(skill_texture)
 
 apply_impulse(Vector2(), Vector2(axe_speed, 0).rotated(rotation))
 self_destruct()
 
func self_destruct():
 yield(get_tree().create_timer(life_time),"timeout")
 queue_free()
 
func _on_Taxe_body_entered(body):
 get_node("CollisionPolygon2D").set_deferred("disabled", true)
 if body.is_in_group("Enemies"):
  body.on_hit(damage)
 self.hide() 


and in the player script  i have this 


func skill_loop():
 if Input.is_action_pressed("shoot")and can_fire == true:
  can_fire = false
  throwing = true
  speed = 0
  get_node("PlayerAxis").rotation = get_angle_to(get_global_mouse_position())
  var axe_instance = axe.instance()
  axe_instance.position = get_node("PlayerAxis/axePosition").get_global_position()
  axe_instance.rotation = get_angle_to(get_global_mouse_position())
  axe_instance.skill_name = selected_skill
  get_parent().add_child(axe_instance)
  yield(get_tree().create_timer(rate_of_fire),"timeout")
  can_fire = true
  throwing = false
  speed = 70

you have to use str(skillname). Where do you get the error invalid type in Vector2 constructor. cannot convert argument 1 from nil to float. ?

Klagsam | 2019-12-14 09:17

in this line

apply_impulse(Vector2(), Vector2(axe_speed, 0).rotated(rotation))

i Writed as Xtremezero said and declared the var skill_name = " " but then i got the error invalid type in Vector2 constructor. cannot convert argument 1 from nil to float.

Erraco | 2019-12-14 15:59

:bust_in_silhouette: Reply From: Xtremezero

in the first declaration in line 4 , you wrote this :

var skill_name

but godot can’t assume what’s the type of it , so instead you should write

var skill_name = “”

This should fix it , (I hope)

i tried as you said and i get the same error like if i tried to command the skill_name to be converted to a string for this purpose using load(“res://graficos/Skills/” + str(skill_name) + “.png” in the line 21.

then i get this error in the line 24 invalid type in Vector2 constructor. cannot convert argument 1 from nil to float.
apply_impulse(Vector2(), Vector2(axe_speed, 0).rotated(rotation))

Erraco | 2019-12-14 16:03

apply_impulse obviously expects a float variable as first argument, not an empty Vector2().
Did you write that function on your own? Could you please show it?

Klagsam | 2019-12-14 16:32

I declared the variable axe_speed as float and the skill_name var as Xtremezero said
and now the code works
No, the code is not my own, I have been following the Game Development Center tutorial about skill bars
Thank you guys so much for helping!

Erraco | 2019-12-14 17:09

ah glad you got it by yourself , I totally forgot to reply to the 2nd part of the question ^^

Xtremezero | 2019-12-14 21:47