![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lokigamer00 |
Hi, sorry if I do not understand is that I am Spanish and I am using the google translator
my problem is the
next:
I want to make every 2 seconds an object (my enemy) be generated randomly between a place, everything is correct but I got the error of attempt to call function ‘set_offset’ in base ‘null instance’ on a null instance.
I am using kinemasticBody2D and I cannot use another. Help pls this is the code
extends Node
var Roca = load("res://Enemigo.tscn")
export (int) var Score
onready var Enemigo = load("res://Enemigo.tscn")
func _ready():
randomize()
func nuevo_juego():
Score = 0
$InicioTimer.start()
$UI.mostrar_mensaje("Listo!")
$UI.update_score(Score)
func _on_InicioTimer_timeout():
$DisparoRapido.start()
$ScoreTimer.start()
$Timer1.start()
func _on_EnemigoTimer_timeout():
$enemigos/Posicion.set_offset(randi())
var NewEnemigo = Enemigo.instance()
get_parent().add_child(NewEnemigo)
NewEnemigo.position = $enemigos/Posicion.position
func _on_ScoreTimer_timeout():
Score += 1
$UI.update_score(Score)
func _on_DisparoEnemigo_timeout():
var DisparoEnemigo = true
func game_over():
$ScoreTimer.stop()
$EnemigoTimer.stop()
$UI.game_over()
func _on_Timer1_timeout():
$EnemigoTimer.start()
I clarify that I am using a node for that but the enemy is a kinemasticBody2D
The func of the error is the following (it is in the complete code)
func _on_EnemigoTimer_timeout():
$enemigos/Posicion.set_offset(randi())
var NewEnemigo = Enemigo.instance()
get_parent().add_child(NewEnemigo)
NewEnemigo.position = $enemigos/Posicion.position
$enemigos/Posicion.set_offset(randi())
that is the line of error