+1 vote

I have two variables:

# source of variable - AStar2D id (type: int)
var point = 604
# Vector2 of two ints
var map_size = Vector2(100, 100) 

When I try

return point % map_size.x

I get this error (Invalid operands 'int' and 'float' in operator '%')

in Engine by (68 points)

1 Answer

+1 vote
Best answer

Vector2 uses float numbers. x and y are float. Using ints to make one does not determine its type.

% only works on integers.
So if you want to use this operator you must cast to integer:

return point % int(map_size.x)
by (28,966 points)
selected by

note if the map_size is not exactly integer sized this will simply cut off anything after the decimal point. which is probably what you want anyway but something to keep in mind.

Well this is unexpected, Should've checked docs.
I hoped duck typing did all the job for me :P Thank you!

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 [email protected] with your username.