Cannot resolve this error, Script does not run, problem with @explore

Godot Version

Godot 4.1.1

Question

Having a problem with @explore

here is the code

extends Node

@export (PackedScene) var Ball # This line specifically is the problem

func _input(event):
if event.is_action_pressed(“click”):
var new_ball = Ball.instantiate()
new_ball.position = get_viewport().get_mouse_position()
add_child(new_ball)

Error message is as follows;

Annotation “@export” requires at most 0 arguments, but 1 were given.

I got this script from a tutorial that was based in godot 3.something.

I’ve tried resolving this by removing the parenthesis etc, or putting the variable = PackedScene yet i get a different error every time or the script doesn’t run.

I’m new to Godot and am watching tutorials to get a feel of the engine and the language as I’m also not a very skilled programmer. Therefore i would really appreciate if anyone could help resolve this error.
Thank You!

the syntax in godot 4 is this:
@export var Ball: PackedScene

1 Like

Thanks, Hope I’m not being a bother but i tried it and the scene quits and gives an error: Cannot call “instantiate” on a null value, and shows new_ball as a null value, if its not troublesome can you give any guidance?

Well, exporting a variable creates a property in the editor, you should see a “Ball” property on the right side when you click your node with all it’s other properties.
You should drag and drop you ball scene into that slot to use it in your script. (or press load from the drop down menu and select your ball scene). By default it’s null, that’s why it doesn’t work

1 Like

THANK YOU SO MUCH!!! It worked.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.