I get a different invalid error “Invalid get index ‘-1’ (on base: ‘int’)”
Lynn_Len | 2018-11-30 20:42
That second error you get is very confusing. It basically means player is an integer, but you declared it as an array, so… Oo
I don’t understand what’s going on. It’s like some other place in your code sets player to be an integer.
Seems, your problem is related to input handling. if event is InputEventMouseButton fires write_component() twice: on mouse press and on mouse release. You getting an error because you’re deleting an entry from player array.
Try to do the following things
Add event type checks to _input method, i.e.
if event is InputEventMouseButton and !event.pressed:
# code on ANY mouse button release
# remove `!` to handle a mouse press event
Add some checks of player array size to write_component method, i.e.
if player.empty():
return
You still have to access your data without using player twice.
P.S.: print() method is really handy to debug input events. And you should never access an array by index before checking its length.