0 votes
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.

Godot version 3.3.2
in Engine by (40 points)

1 Answer

+2 votes
Best answer

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 ...
by (418 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.