0 votes

I have been making a small program where a box should spawn on my cursor every five seconds but when five seconds pass I get this error

Invalid set index 'position' (on base: 'Vector2') with value of type 'Vector2'.

here is my code

extends Node

var box = preload("res://box/Box.tscn")

func onTimertimeout():
var pos = get
viewport().getmouseposition()
pos.position = Vector2(pos.x, pos.y)
add_child(box)

in Engine by (12 points)

1 Answer

0 votes

You wrote pos.position, but pos is the mouse position, so it's a Vector2. A Vector2 doesn't have a position property, so that's why you got an error.

I't snot clear what you're trying to do. You're not spawning any box. If you wanted to do that, you'd need to call instance() on your box PackedScene. In that case, you probably want to do box.position = pos to set the box's position to the mouse position.

by (21,714 points)
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.