randomize scenes

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

Hello, my doubt now is about range:

I have 3 tilemaps in 3 scenes:

I have a collisionshape at the end of my tilemaps
when my player collides to it, I want to create randomly map1,or 2 or 3.

How do I get it?

:bust_in_silhouette: Reply From: Elis

If you’re familiar with the method of load and instance, you can do something like:

var alpha = load("res://yourpath/map" + str(randi()%3 + 1) + ".tscn")
var alphainstance = alpha.instance()

I hope it’s a solution to your problem

thanks, it worked!!

CB | 2019-02-25 01:57

hello Ells , it’s me again

when I write the code in func _ready it woks only three times

I want its works infinitelly

it’s an infinity runner.

I create a collision shape (segmented), when my player collides on it
I want it creates ramdonly.

CB | 2019-02-25 12:04


I’m not sure I understand your problem. If I’m right, you want to create a game with kind of the same mechanic as “Jetpack Joyride”, which create random scenes/environments every few screens. When working on a game, I would advise you to visualize what you want to do.

(Please keep in mind that it’s only how I would do it, but you can make your own better solution).

(It’s through the editor, not though)

I believe that with this way of doing it, your problem of the generation only working sometimes should disappear.

Does it seem right to you?
Btw, if you’re discovering the randi()% function, I would advise you to call randomize() at the start of your game, it will create a random set of number for your randi()% to use.

Elis | 2019-02-25 12:28

Hello Elis I’ve tried to do the way you’ve said

it worked

but each time the scene is created, it increases the velocity

forgive me, my english is very poor

CB | 2019-02-28 00:10