0 votes

code:

func _process(delta):
    move_and_collide(Vector3.DOWN * fallingSpeed * delta)
    if Input.is_action_pressed("ui_up"):
        move_and_collide(transform.basis.x * moveSpeed * delta)
    if Input.is_action_pressed("ui_left"):
        rotate(Vector3.UP, +rotatingSpeed * delta)
    if  Input.is_action_pressed("ui_right"):
        rotate(Vector3.UP, -rotatingSpeed * delta)

    if Input.is_action_just_pressed("ui_accept"):
    var b = Bullet.instance()    <------- error
    owner.add_child(b)  
    b.transform = $Cannon/Muzzle.global_transform
    b.velocity = -b.transform.basis.z * b.muzzle_velocity

    pass

im using 3.3. followed the tutorial on
https://kidscancode.org/godot_recipes/3d/3d_shooting/

i'm trying to make a firing mechanism but one line shows an error. might someone hase a solution?

Godot version 3.3
in Engine by (221 points)
edited by

Two tips:

1) When you post your code, it becomes unreadable unless you format it correctly. The "code sample" button in the editor here on QA will fix that. I've edited your post to fix it this time.

2) No one can solve your error if you don't say what the error was. The error message contains very important information.

The indentation after if Input.is_action_just_pressed("ui_accept"): is still a problem.

Yes, but I wasn't sure if that was the error or if it's something else. Let's see what the error message they are getting is.

i dont know what the error message is, but i just try by guessing it,
if the error is in this line:

var b = Bullet.instance() <------- error

maybe there are some possible problem, if the indentation is not the problem, and i dont know how "relative new" you are, but are you just write this line:

export (PackedScene) var Bullet

without load the scene from the inspector?, sometime i forgot about this too, and im also relative new to godot, hope this can be help, im sorry if im wrong

Ports and connections in Godot Visual Scripting

7 Answers

+1 vote

I think you should drag bullet scene from the filesystem to Bullet property in the inspector or convert

export (PackedScene) var Bullet

into

export (PackedScene) var Bullet = "res://Bullet.tscn"
by (939 points)

for instancing a scene you need to specify its address then use instance() and finally add_child(). and here i think you missed to specify the path

Hope you got my point :)

0 votes

hi, thanks for the help, but should i have made a own scene for the bullet?
(i didn't)

by (221 points)
0 votes

sorry, forgot to say, the error was "expected an intended block after if."

by (221 points)
0 votes

First yes you should have made an own scene for the bullet as the type of the var Bullet is a PackedScene else creating instances etc. won't work. Your error "expected an intended block after if" means simply that you need some code after your if statement which needs to be for formated/indented correctly with 4 spaces like you did with the if statements in the beginning of the function. Long story short:

if statement:
    #code goes here
by (16 points)
edited by
0 votes

Given that error means you need to indent as below. Make sure you are consistent with how you indent either using tabs or spaces for all your indents. Don't mix spaces and tabs sometimes it happens when you copy/paste code from websites :
https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_styleguide.html

func _process(delta):
    move_and_collide(Vector3.DOWN * fallingSpeed * delta)
    if Input.is_action_pressed("ui_up"):
        move_and_collide(transform.basis.x * moveSpeed * delta)
    if Input.is_action_pressed("ui_left"):
        rotate(Vector3.UP, +rotatingSpeed * delta)
    if  Input.is_action_pressed("ui_right"):
        rotate(Vector3.UP, -rotatingSpeed * delta)

    if Input.is_action_just_pressed("ui_accept"):
        var b = Bullet.instance()    <------- error
        owner.add_child(b)  
        b.transform = $Cannon/Muzzle.global_transform
        b.velocity = -b.transform.basis.z * b.muzzle_velocity

    pass
by (805 points)
0 votes

thanks for the help, but now if i press ui_accept (space) it crashes and gives me this errormessage: "invalid call:Nonexistent 'function' instance in base 'NIL' "

by (221 points)

By the way, you should use "Comment" instead of "Answer". That way they'll get an email notification.

0 votes

ok, god it.
thanks you all

by (221 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.