Topic was automatically imported from the old Question2Answer platform.
Asked By
AwYiss
So basically ive been working on a random terrain generation thats 2d, im not using simplex just yet as im still trying to get a hang of things but basically whenever i try to for loop a randi it gives me out of parameter answers but i think it has something to do with my variables since i do this:
var h = 10
var loop = 5
func ready():
for x in 5:
var a = h - 1
vat b = h + 1
var random = randi()%b + a
What exactly is happening here and how do i fix it?
I’m not sure what you’re trying to do. What do you mean by out of parameters? Currently the code gives you numbers that are between 9 and 20.
exuin | 2021-04-01 00:06
What is the range expected? This could greatly help in finding the solution.
Bubu | 2021-04-01 07:02
i wanna find a random number that would give me numbers from 9 to 11 while using the
the h as a parameter for a for loop
AwYiss | 2021-04-01 07:16
How come 20? when b should be 11??? also im trying to make a random terrain generation without using simplex but instead using a tile map and for looping.
AwYiss | 2021-04-01 07:19
9 and 20? not 9 and 11? how? also what i mean by out of parameters is it goes from expected maximum which should be 11 and expected minimum which should be 9 no?
To get numbers between 9 and 11 you want randi() % 3 + 9. The randi function gives you a random integer and using modulus on it gives you a range of numbers. Then adding to that result will shift the range up.