invalid get index 'MOUSE_BUTTON'(on base GDscriptNativeClass)..how do i solve this?

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

{enter code here**extends KinematicBody2D

const ball_scene = preload(“res://mini scenes/ball.tscn”)

func _ready():
set_physics_process(true)
set_process_input(true)

func _physics_process(_delta):
var y = get_position().y
var mouse_x = get_viewport().get_mouse_position().x
set_position(Vector2(mouse_x, y))

func _input(event):
if event is InputEvent.MOUSE_BUTTON && event.is_action_pressed():
var ball = ball_scene.instance()
ball.set_position(get_position() - Vector2(0, 16))
get_tree().get_root.add_child(ball)

}

:bust_in_silhouette: Reply From: kidscancode

InputEventMouseButton is a type:

So your code should be:

if event is InputEventMouseButton and event.pressed:

PS - you can format your code here using the {} formatting button when you paste it in.

Thank you so much. And your channel is amazing

Beizey | 2020-11-22 13:13

:bust_in_silhouette: Reply From: jgodfrey

That should read…

if event is InputEventMouseButton ...

Thanks a lot for helping me

Beizey | 2020-11-22 13:13