Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ouhellouder |
i have
enum {
shelf
window
hall
}
var state
func _ready():
randomize()
func _process(_delta):
match state:
shelf:
var shelf = $hotovaskrinaotvorena
print ("shelf")
hall:
var TSP = $MainHall/Teddyspawnpoint
var spawnteddy = Teddy.instance()
add_child_below_node(TSP, spawnteddy)
print("hall")
window:
print ("window")
pass
func choose(array):
array.shuffle()
return array.front()
func _on_Timer_timeout():
state = choose([hall,shelf,window])
After this all it spawns my NPC but its spawning it till new is choosed or my game crushed is any solution for this? if is please respond
I’m not sure what you’re trying to do. But, it looks like you have a timer (not sure what its interval is) that picks one of 3 elements of your array. If the selected element is hall
, you add a new node to the scene in every frame. Yikes…
That can’t be what you intend. What are you actually trying to do here?
jgodfrey | 2021-01-06 20:09
what i wanna do is like you said add_child to be more accurate instance scene then add that scene as child bellow node but every as i made some tests it runs this
hall:
var TSP = $MainHall/Teddyspawnpoint
var spawnteddy = Teddy.instance()
add_child_below_node(TSP, spawnteddy)
print(“hall”)
but its adding new childs till new state is picked i tryed to remove return then game dont crushed but it also dont add child becouse when
func choose(array):
array.shuffle()
return array.front()
runs that return means( returns value that has been choosed ) and i dont know how to fix that or make some other function same as func Choode(array):
ouhellouder | 2021-01-07 07:45