Hello B)
Im trying to set up at script that by itself finds out what type of fish (in this case swimmer) it is and assigns its own speed and value accordingly. Unfortunately it seems that my process to grab a specific key from the array is wrong but im not actually sure how to fix it
var swimmer_types = [
{"name" : "orange fish", "speed" : 5, "points" : 1},
{"name" : "red fish", "speed" : 10, "points" : 2},
{"name" : "trash", "speed" : 3, "points" : -1}
]
var my_points : int = 0
var my_speed : float = 0
# Called when the node enters the scene tree for the first time.
func _ready():
_assign_type()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
func _assign_type() -> Array:
for type in swimmer_types:
if self.is_in_group(swimmer_types[type]["name"]): <-error is here?
my_points = type["points"]
my_speed = type["speed"]
return [my_speed, my_points]
func _on_area_2d_body_entered(body):
if body.is_in_group("player"):
print(my_points, my_speed)```
if clarification or more details are needed let me know