0 votes

So I've just been making a simple grid based game and I was trying to find a way to read if some adjacent block that the player was trying to move into was a wall piece (which has an ID of 2.) When I finished it up it ran for a little while and then when I started to move it wouldn't stop and give me this error. Any insights?

 ##All extensions and imports that the script needs:
    extends Sprite
    onready var map = get_parent()
    onready var tween = get_node("../../Tween")
    ##All Exported Variables
    export var TileSize = 16 ##This is the size of the tileset.
    export var MoveAllowance = .25 ## this is the time that the player must wait before the next move is taken.

    ##All Internal Variables:
    var timeDelay = 0
    var mapGoal = Vector2(0,0)
    var pos = Vector2(0,0) ##This will be where the player is.
    var goalPos = Vector2(2,2) ## This is where the player wants to be.
    var  levelMap1 = []
    ##This will happen Only at the beginning of the game.
    func _ready():
        self.position = Vector2(0,0)

    ##This will happen at every tick of the game.
    func _process(delta):
        pos = self.position
        if  timeDelay == 0:
            mapGoal = self.get_position() + goalPos
            if levelMap1[mapGoal.x][mapGoal.y] == 2:
            timeDelay = 1 ##this can be edited to determine how long the player must wait before moving.

            ##goalPos = Vector2(0,0)
        #elif timeDelay > .2:
            timeDelay += -MoveAllowance

    ##getInput Simply loads the next input into the _process function for processing.
    func getInput():

            if Input.is_action_pressed("ui_right"):
                goalPos.x += 1
            elif Input.is_action_pressed("ui_left"): 
                goalPos.x += -1
            if Input.is_action_pressed("ui_up"):
                goalPos.y += -1
            elif Input.is_action_pressed("ui_down"):
                goalPos.y += 1

    func tweener(object,location1,location2,speed): ##this script will smooth out the position changes of anything.
        tween.interpolate_property(object, "position",
                    location1, location2, speed,
                    Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

    ## this just scans the nearby area and get the results.
    func threeByThree():
        levelMap1 = map.get_used_cells()
        ##var xCheck = -1
        ##while xCheck<2:
        ##  var yCheck = -1
        ##  while yCheck = -1
        ##  xCheck = xCheck + 1

Thanks again,

Edit 1: I realized I forgot to mention which error it gave me.
The error was: Invalid get index (on base: 'Vector2'). Thanks again!

in Engine by (92 points)
edited by

There are some random commented out things that I was playing around with, just ignore those if you can. And sorry for how inelegant it all is, I'm not very proficient.

it would stop and give me this error

Which error?

You mentioned an error, but instead of putting said error up where we could see it, you gave us the script. We can't help you with your error if you don't show the error itself.

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.