0

I added sound to my game, but after I played my game for a few clicks it would close and say (Attempt to call function'play' in base 'null instance' on a null instance) and I went to stack exchange and they said there was something wrong with my indentation on my first two functions and to come here for indentation help.

I tried indenting the first two, but it still wouldn't work and i would get more errors saying 'Unexpected Indent' or Parser Error: Unindent does not match any other indentation level.

func _ready():
    position = get_viewport_rect().size / 2
    direction.x = rand_range(-1, 1)
    direction.y = rand_range(-1, 1)
    direction = direction.normalized()
    width = get_viewport_rect().size.x
    height = get_viewport_rect().size.y

func _process(delta):
    position += direction * speed * delta
    if position.x < 0 or position.x > width:
        direction.x = -direction.x
    if position.y < 0 or position.y > height:
        direction.y = -direction.y

func _on_UFO_input_event( viewport, event, shape_idx ):
    if lose:
     return 
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
        direction.x = rand_range(-1, 1)
        direction.y = rand_range(-1, 1)  
        direction = direction.normalized()
        position.x = rand_range(1, width -1)
        position.y = rand_range(1, height -1)
        speed += 5      
        hit = true
        $HitSound.play()

I expected the sound of my game to play but after a few clicks it shuts down and says (Attempt to call function'play' in base 'null instance' on a null instance)

  • `Attempt to call function'play' in base 'null instance' on a null instance` in Godot means that Godot cant find the node you're specifying, usually due to a path error, but occasionally a misspelling (case-sensitive). If you want to call it using `$HitSound` (using $), try making the AudioStreamPlayer a child of the node with the script attached. Otherwise, look into specifying the path to the `HitSound` node more precisely. – Christopher Bennett Jun 05 '19 at 12:41
  • Ok thank you so much i'll give that a shot – Najma Muhammad Jun 05 '19 at 13:40
  • No problem. If it doesn't work for you, let me know. I'm at work right now, so I don't have time to explain it better, but I can post a more clear explanation/solution later on if you still need. – Christopher Bennett Jun 05 '19 at 13:50
  • Thank you it was a misspelling when i spelled the node i type HItSound instead of HitSound thank you so much – Najma Muhammad Jun 05 '19 at 13:59
  • No problem. Glad you found it. – Christopher Bennett Jun 05 '19 at 14:21

0 Answers0