I don't understand your script or what you are trying to do but I have been using arrays for a project of mine and see some things that may explain the crashing.
it is very hard to give an informed answer because there is not enough information here to address your whole question.
I cant see any reason that the player could go infinitely left, there is only three index's and three moves , it would crash going to the right because there is nothing there to stop the index value from being less than zero so you are requesting a position from the array at index - 1.
I don't understand func _ready() and how that works with Yakuza instances. if you want the instances locations in an array then signal the player script @ instancing the new Yakuza so that signal would be in the Yakuza script or where ever they are instanced , in the signal you can send a reference to the Yakuza or its location , what ever works better.
so in the yakuza script
signal yakuza_placed
func instance_yakuza():
var position = Vector2(100, 100) # or what ever position
var scene_instance = scene.instance()
scene_instance.global_position = position
add_child(scene_instance)
emit_signal("yakuza_placed", position)
then in the player script
var min_position_index = 0
var max_position_index
var position_index = 0
func _on_yakuza_placed (position): # where the signal is recieved
positions.append(position)
max_positions_index = positions.size() - 1 # first index in an array is zero so .size() - 1
positions.sort()
#it reads to me like what is happening in the position array is going up and down the sorted array , so I am not sure on calling to find the current index.
if Input.is_action_just_pressed("ui_right"):
position_index -= 1
if position_index < min_position_index:
position index = min_position_index
if Input.is_action_just_pressed("ui_left"):
position_index += 1
if position_index > max_position_index:
position_index = max_position_index
$Player.global_position = positions[position_index]
for the part about wanting to send the outcome of the input event to a different script , I just don't understand that , if you want the input event in a different script then just test for the input event in that script in the first place, don't use a signal where you don't need to, they can start getting pretty confusing.
I am new to Godot and not sure that this is helpful or not , in all likelihood all of my syntax may not be right :-) but I hope it is helpful. I have been using arrays for my project and use a few different ways to go through them , so hopefully it is helpful...