Specify type from concrete scene - GDScript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Oliver Tušla

Hi,
I am now going through Your first game tutorial and at the end of the Main script section (https://docs.godotengine.org/en/3.1/getting_started/step_by_step/your_first_game.html#main-script) there is a _on_MobTimer_timeout function.

Mob is exported at the top of Main script export (PackedScene) var Mob and the Mob scene is added in the editor.

However I don’t get intellisense for the exported variable in Mob script min_speed and max_speed.

Is there a way to type the mob variable such that it indicates those exported variables?

I have tried typing it as RigidBody2D which didn’t work (of course) and casting using as Mob didn’t help either (The RigidBody2D node in Mob scene is named Mob).

Thanks in advance

:bust_in_silhouette: Reply From: Vrzasq

Hi,

Currently You can export only godot build in types like Resource, Vector2 etc. You can find more about exporting here:

and about loading / preloading resources here:

You can get code completion with couple ways, but at first I suggest that You register Mob class inside Mob.gd like that

extends RigidBody2D
calss_name Mob

And than inside Main.gd You can do something like that

export(PackedScene) var MobScene
...
func _on_MobTimer_timeout():
...
    var mob := MobScene.instance() as Mob

or instead of exporting You can preload from path.

var mob = preload("res://Mob.tscn").instance() as Mob

Hope this helps