0 votes

I have the following code:

var Location = Vector2(64, 64)

if Location[0] > 911.0:
        Location[0] = 64.0
        Location[1] = Location[1] + 64.0
        Location = Location[0] + 112.0
    return Location

I have also tried this with using .x instead of [0] and .y instead of [1].

I get the following error:

Invalid get index '0' (on base: 'float').

or if I use .x instead of [0] I get:
Invalid get index 'x' (on base: 'float').

So that makes me think that it is somehow a float, so I try getting rid of the index altogether and then it says:
Invalid operands 'Vector2' and 'float' in operator >

How do I check what the x value is and then change it?

Godot version 3.5
in Engine by (20 points)

1 Answer

+2 votes
Best answer

You can use either Location[0] and Location[1] or Location.x and Location.y.

Specifically, your problem is here:

Location = Location[0] + 112.0

There, you're trying to set Location (which is a Vector2) to a floating point value. I assume you mean Location[0] += 112

Really, you can do the above like this:

var Location = Vector2(64, 64)
if Location.x > 911.0:
    Location.x = 64
    Location.y += 64
    Location.x += 112
by (16,712 points)
selected by

Holy nuts, of course. That seems super obvious now. Thanks for your help.

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.