0 votes

So I'm trying to make a random blocks generator on a certain area, here's my code, when I test how many children the generator node has after it was meant to duplicate the node it says 1, and only 1 block was randomized on the game when I play it, by my testing there is some problem with the duplicate() function, it just doesnt duplicate the block

func RandomTilePosition():
var x = randrange(-7, 6) #Generates a X position
randomize()
var z = rand
range(-7, 6) #Generates a Z position
randomize()
var returning = Vector3(round(x) + 0.5, 1.5, round(z) + 0.5) #sets a variable to what I need to return, to test it later
if not returning == Vector3(-6.5, 1.5, 6.5): #tests if its not the exact place the player will spawn
return Vector3(round(x) + 0.5, 1.5, round(z) + 0.5) #gives the randomized value when you use the function

var Walls = []

func ready():
if Global.difficulty == 1: #this is for a thing on my game, ignore
for count in range(3): #duplicates the block 3 times
Walls.insert(Walls.size(), RandomTilePosition()) #saves the random number on a list to use it later
get
node("Wall").translation = Walls[count] #sets the position of the block to then duplicate it on the right area
print(Walls[count])
getnode("Wall").duplicate() #this is the part that I think is not working, and by what I saw its the only way to duplicate
print(get
child_count())

enter image description here

enter image description here

enter image description here

Godot version 3.4.2 stable
in Engine by (15 points)

Please format the code with the code sample button or markdown.

1 Answer

+1 vote
Best answer

You need to add_child() after you duplicate! :)

Eg.

Var newNode=oldNode.duplicate()
Add_child(newNode)
by (1,290 points)
selected by

Thank you so much, it worked so well by addchild(getnode("Wall").duplicate())

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.