I'm trying to export my game to html on itch.io and it works perfectly well when I test it on my pc but when I try to play it in the browser it gives me this: _on_EnemyTimer_timeout (res://src/Scripts/Main.gdc:45) - Attempt to call function 'instance' in base 'null instance' on a null instance. and this: Attempt to call function 'instance' in base 'null instance' on a null instance.
here is the script the error comes from
extends Node2D
var rng = RandomNumberGenerator.new()
onready var Enemy1 = load("res://src/scenes/enemy1.tscn")
onready var Enemy2 = load("res://src/scenes/enemy2.tscn")
onready var Enemy3 = load("res://src/scenes/enemy3.tscn")
var UpgradeScreen = load("res://src/scenes/upgradescreen.tscn")
var TimeMult = 1
func LevelUp():
var US = UpgradeScreen.instance()
$UI.add_child(US)
$UI/LevelBar/LevelBar.value = 0
$UI/LevelBar/LevelBar.max_value *= 1.1
$Player.Level += 1
get_node("/root/VarManager").Level += 1
func _ready():
rng.randomize()
func _process(delta):
if $UI/LevelBar/LevelBar.value >= $UI/LevelBar/LevelBar.max_value:
LevelUp()
$UI/LevelBar/Label.text = "Level " + str($Player.Level)
$UI/HealthBar/Label.text = str($Player.hp)
$Score/Label.text = str(get_node("/root/VarManager").Score)
func _on_EnemyTimer_timeout():
var pos = Vector2(rng.randi_range(-200, 1224), rng.randi_range(-200, 800))
var type = null
while pos.x > 0 and pos.y > 0 and pos.x < 1024 and pos.y < 600:
pos = Vector2(rng.randi_range(-200, 1224), rng.randi_range(-200, 800))
var num = 0
if $Player.Level >= 5:
num = 1
else:
type = Enemy1.instance()
if $Player.Level >= 10:
num = 2
type = rng.randi_range(0, num)
match type:
0:
type = Enemy1.instance()
1:
type = Enemy2.instance()
2:
type = Enemy3.instance()
$Enemies.add_child(type)
type.position = pos