How do i spawn objects on random position but inside the screen (2D)

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

I am trying to make a popup bar and i want it to show in a random position
inside the screen.

:bust_in_silhouette: Reply From: AkioTheGreat

no i found the solution. for me its
(pblock means popup)

var Pblock = preload("res://Popup4.tscn")

(i added a timer so when its timeout, it will play this method)
Random:

var Pblock_instance = Pblock.instance()
Pblock_instance.set_position(Vector2(rand_range(-200,200), rand_range(-100, 200)))
add_child(Pblock_instance)