I actually have problem for adding random blocks in my game, I'll will be happy to help me with the code.

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

I actually have problem for adding random blocks in my game, I’ll will be happy to help me with the code.

Let me explain why you are receiving only down votes on this question: Do not expect someone to just provide ready-made code to do what you ask. Instead show some effort. What have you tried so far? Share the code you are currently trying to make add random blocks. Tell us what’s working and what’s not. Have you tried to implement some random-block-algorithm based on some tutorial on the webs? Which one?

I’m sorry if this comes out too blunt, but you won’t be able to make the next Minecraft by asking this kind of questions and gluing the answers together. You’ll have to go to the documentation and read how RandomNumberGenerator works in GDScript and then ask questions if/when you get stuck.

J4-G0 | 2021-11-12 11:28

Thanks for your tips, I’m sorry It was my first time. I will be edit this and share my code as soon as possible.

kiana | 2021-11-12 22:04

:bust_in_silhouette: Reply From: Gluon

You can set a var as your location like

onready var Sprite_position = Vector2()

set your sprite for an instance like

Sprite_inst = preload("res://Sprite.tscn")

and then you can use the randrange to set its positions for example

Sprite_position.x = rand_range(1, 100)
Sprite_position.y = rand_range(1, 100)

create an instance of your sprite like this

Var New_sprite = Sprite_inst.instance()

and then put it in the random position you created with

New_sprite.position = Sprite_position

finally add it to the scene

add_child(New_sprite)

Hope this helps.