![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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