For loops give me an object instead of an integer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rubin
for x in players:
    print(typeof(x), " ", x) # x is of type "object", not "int"
	if players[x].id == player_id:
		players[x].pos = pos
		players[x].rot_y = rot_y
		break

Hello! I’m trying to do a for loop on the array “players” but the variable “x” somehow is of type object.

:bust_in_silhouette: Reply From: spaceyjase

And what type is players? If x is an object, you operate on it directly:

for x in players:
    if x.id == player_id:
        x.pos = pos
        x.rot_y = rot_y
        break

If you want to iterate using an index, code it as such:

for x in range(players.size()):
    # ... code ...