![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Decisive |
Basically i have a variable named current group, and another four variables named: right, left, down, up. And then everytime a button is pressed i remove from the current group and set it as the new one for that action, but godot give me the error: “Invalid type in function ‘remove_from_group’ in base ‘KinematicBody2D (UWU.gd)’. Cannot convert argument 1 from Nil to String.”
Here’s the code
var current_group = down
#Variables that store the groups
var right = “LR”
var left = “LL”
var up = “LU”
var down = “LD”
func _ready():
self.add_to_group(“LD”)
if self.is_in_group("LD"):
print("it works mate!")
if self.is_in_group("LR") and self.is_in_group("LD"):
print("works here too")
func get_input():
velocity = Vector2.ZERO
if Input.is_action_pressed(‘right’):
self.remove_from_group(current_group)
current_group = right
self.add_to_group(right)
velocity.x += 1
if Input.is_action_pressed(‘left’):
velocity.x -= 1
self.remove_from_group(current_group)
current_group = left
self.add_to_group(left)
if Input.is_action_pressed(‘down’):
velocity.y += 1
self.remove_from_group(current_group)
current_group = down
self.add_to_group(down)
if Input.is_action_pressed(‘up’):
velocity.y -= 1
self.remove_from_group(current_group)
current_group = up
self.add_to_group(up)