Community Forum

os.clock() not work in a LUA for FS 15?

Forum Overview >> Scripting

Created07.08.2016 09:35

Kevin I. (Ifkonator2) 07.08.2016 09:50
Hello everyone!

I try at the moment to use 'math.randomseed()' for 'better' random numbers . But when i set the Value for this like this:

math.randomseed(os.time() - os.clock() * 1000);

The game will be stuck with this error:

Error: Running LUA method 'update'.
C:/Users/Kevin/Documents/My Games/FarmingSimulator2015/mods//FS15_Erntepack_by_Modding_Welt/Scripts/StrobeLights.lua:107: attempt to index global 'os' (a nil value)

I know, the error means, that 'os' is nil, but i don't know why?

Here a picture of my Script:

I don't know how i use 'math.randomseed()' now correct for FS 15.. Everywhere are examples with os.time(), but this not work here..



Bjoern J (Bluebaby210) 14.08.2016 10:24
for a better "math.random" i use "math.randomseed(g_currentMission.environment.dayTime)". For more different values, use higher values, maybe like this:
the result will be a number between 0.98 and 1.2.

Sebastian Sbsh (s4t4nsbsh) 20.12.2022 15:54
has anyone an idea, how it works in FS22 with math.randomseed?
g_currentMission.environment.timeAdjustment or g_currentMission.environment.dayTime gives a nil

Loki Laufeyson (loki_79) 21.12.2022 13:32
How are you calling it, maybe before the g_currentMission has been created?

dayTime exists for me in FS22: g_currentMission.environment.dayTime = 41542049.562468

Note: Log in to post. Create a new account here.