i’m trying to make a firing mechanism but one line shows an error. might someone hase a solution?
Two tips:
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.
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
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:
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
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.