Hi all,
I’m currently trying to create a factory that will randomly set the locations of the created objects. I’ve tried two methods to create these random values. One of them makes each value different, and the other results in all three values being the same random number.
math.randomseed(os.time())
factory.create("/worm_spawner#worm_factory", vmath.vector3(250,250,1), nil, { local_pos = math.random(-75, 75), bool = math.random(0, 1)}, .25)
factory.create("/worm_spawner#worm_factory", vmath.vector3(200,200,1), nil, { local_pos = math.random(-75, 75), bool = math.random(0, 1)}, .25)
factory.create("/worm_spawner#worm_factory", vmath.vector3(550,400,1), nil, { local_pos = math.random(-75, 75), bool = math.random(0, 1)}, .25)
V1: all three local_pos values are the same
math.randomseed(os.time())
x1 = math.random(-75, 75)
x2 = math.random(-75, 75)
x3 = math.random(-75, 75)
factory.create("/worm_spawner#worm_factory", vmath.vector3(250,250,1), nil, { local_pos = x1, bool = math.random(0, 1)}, .25)
factory.create("/worm_spawner#worm_factory", vmath.vector3(200,200,1), nil, { local_pos = x2, bool = math.random(0, 1)}, .25)
factory.create("/worm_spawner#worm_factory", vmath.vector3(550,400,1), nil, { local_pos = x3, bool = math.random(0, 1)}, .25)
V2: all three local_pos values are different
My best guess is that the program is calculating one random value with the given parameters and using it for all the instances where it’s called. Is there any way to make the first version work? (I’d like to use loops in the final version of this). Thanks!