Invalid call. Nonexitent function "instance" in base "tileset"

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

Anyone know the solution? it seems that it does not exist “instance” in godot script.

const FIREBALL = preload(“res://groundtileset.tres”)

if Input.is_action_just_pressed(“ui_focus_next”):
var _fireball = FIREBALL.instance()
get_parent().add_child(_fireball)


extends KinematicBody2D

const SPEED = 60
const GRAVITY = 10
const JUMP_POWER = -250
const FLOOR = Vector2(0, -1)

const FIREBALL = preload(“res://groundtileset.tres”)

var velocity = Vector2()

var on_ground = false

func _physics_process(_delta):

if Input.is_action_pressed("ui_right"):
	velocity.x = SPEED
	$AnimatedSprite.play("run")
	$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
	velocity.x = -SPEED
	$AnimatedSprite.play("run")
	$AnimatedSprite.flip_h = true
else:
	velocity.x = 0
	if on_ground == true:
		$AnimatedSprite.play("idle")
	
if Input.is_action_pressed("ui_up"):
	if on_ground == true:
		velocity.y = JUMP_POWER
		on_ground = false
if Input.is_action_just_pressed("ui_focus_next"):
	var _fireball = FIREBALL.instance()
	get_parent().add_child(_fireball)

velocity.y += GRAVITY

if is_on_floor():
	on_ground = true
else:
	on_ground = false
	if velocity.y < 0:
		$AnimatedSprite.play("jump")
	else:$AnimatedSprite.play("fall")

velocity = move_and_slide(velocity, FLOOR)
:bust_in_silhouette: Reply From: kidscancode

instance() is a method of PackedScene:

One way to obtain a packed scene is by loading a scene that’s been saved to disk:

var my_scene = load("res://my_scene.tscn")
var scene_instance = my_scene.instance()

However, you are not loading a scene, you’re loading a TileSet resource - preload("res://groundtileset.tres")

A TileSet is a data resource used by the TileMap node:

Hopefully this helps clear things up a bit. I don’t really understand why you’re trying to use a TileSet resource to instance your fireball object in the first place.

You are right. I was confused. As you said It is meaningless use a Tileset resource. Thank you so much.

David_sun | 2019-09-30 17:53