0 votes

So I'm trying to get something to reference position in GDScript but whenever I reference the methods worldtomap() or maptoworld() and I run the script my program seems to enter an infinite loop and has to be force closed.

func BasicMovement():

if Input.is_key_pressed(KEY_A):
    goalPosition += Vector2(-1,0)
    turnCount = turnCount + 1
elif Input.is_key_pressed(KEY_D):
    goalPosition += Vector2(1,0)
    turnCount = turnCount + 1
if Input.is_key_pressed(KEY_W):
    goalPosition += Vector2(0,-1)
    turnCount = turnCount + 1
elif Input.is_key_pressed(KEY_S):
    goalPosition += Vector2(0,1)
    turnCount = turnCount + 1
SnapToGrid()

pass

func SnapToGrid():
set_position(goalPosition.world_to_map())
pass

What is here that screams infinite loop to you guys?

in Engine by (93 points)

Nothing looks like an infitite loop here, but you should investigate where that infinite loop actually happens. Maybe it's not where you think it is. Try pausing the debugger when that happens and see what the script is doing at this time.
If it doesn't work, try putting two print statements around the location you believe that loop is happening.

Please log in or register to answer this question.

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