hi, i'm relatively new to godot.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By theMX89

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?

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.

kidscancode | 2021-06-04 23:15

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

wyattb | 2021-06-04 23:30

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.

kidscancode | 2021-06-04 23:44

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

nahcode | 2021-06-05 16:34

Ports and connections in Godot Visual Scripting

Themarly | 2021-06-08 00:02

:bust_in_silhouette: Reply From: Help me please

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"

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

Help me please | 2021-06-05 13:53

Hope you got my point :slight_smile:

Help me please | 2021-06-05 14:22

:bust_in_silhouette: Reply From: theMX89

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

:bust_in_silhouette: Reply From: theMX89

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

:bust_in_silhouette: Reply From: Axiot

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
:bust_in_silhouette: Reply From: wyattb

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 :

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
:bust_in_silhouette: Reply From: theMX89

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 the way, you should use “Comment” instead of “Answer”. That way they’ll get an email notification.

exuin | 2021-06-06 13:53

:bust_in_silhouette: Reply From: theMX89

ok, god it.
thanks you all