The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm stumped, how do I fix this? I cant find a solution anywhere else.

extends Position2D

export (PackedScene) var spawnScene
onready var spawnReference = load(spawnScene.get_path())
onready var sprite = get_tree().get_root().get_node("World/Player/PlayerSprite")
onready var sound = get_parent().get_node("World/Player/BulletSpawn/Bullet/Sound")#/Sound").get("Shoot")

#var bullet = self
var velocity = Vector2()
var speed = 1.25
var ammo = 12
var canShoot = true

export var BulletSpeed = 1500.0
export var Smoothness = 0.2

func _ready():

#func _fixed_process(delta):

func _input(event):
    var spawnInstance = spawnReference.instance()
    var direction = 3.0

    if event.type == InputEvent.KEY:
        var key = event.scancode
        var pressed = event.is_pressed()
        var echo = event.is_echo()

        if key == KEY_Q and pressed and not echo:
            ammo -= 1

        elif key == KEY_E and pressed and not echo:
            ammo -= 1
in Engine by (164 points)

1 Answer

+1 vote

You didn't say where exactly in that code the error is happening.

One thing I notice: you use spawnInstance.set_pos(), but set_pos() requires an argument - you have to set the position to something.

Also, this:

func _input(event):
    var spawnInstance = spawnReference.instance()

Is not a good thing. You're spawning an instance of that scene every time the input function is called. But that happens on any input event, including mouse movement, etc.

In general, it's a better idea to use the input map and create input actions for any input you want to process. That way it's easier to change input keys, transition to gamepad or touch, etc.

by (22,191 points)

Whoops, its at line 36 and 43...

So it's what I answered: you have to supply a Vector2 for set_pos() to set the position of a node.

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.