The time is available to Game Engine Lua via the time of day object. Code: local tod = core_environment.getTimeOfDay() local time = tod.time This time is a decimal number from 0-1 that represents 12:00 to 12:00 the next day, so you may need to do some maths. This works to get the time in seconds. Code: (tod.time+0.5)%1*86400 Note that the multiplier is calculated by converting 24h into the required time unit. If you just need hours, use that.
Thank you for help but here's an error says core_environment is a nil value. Code: local M = {} local function init() end local function updateGFX(dt) local tod = core_environment.getTimeOfDay() local time = tod.time dump(time) end M.onInit = init M.onReset = init M.updateGFX = updateGFX return M
You are running in vehicle lua, not game engine lua. https://documentation.beamng.com/modding/programming/virtualmachines/
I see. So can I make the time a electrics value? Or is there any other ways to send it to the vehicle?
I did this and it works. Code: -- ge file local M = {} local function onExtensionLoaded() end local function onUpdate(dt, dtSim) local tod = core_environment.getTimeOfDay() be:sendToMailbox("timeService", tod.time) end M.onExtensionLoaded = onExtensionLoaded M.onVehicleSwitched = onExtensionLoaded M.onVehicleDestroyed = onExtensionLoaded M.onVehicleSpawned = onExtensionLoaded M.onClientPostStartMission = onExtensionLoaded M.registerVehicle = onExtensionLoaded M.onUpdate = onUpdate return M Code: -- ve file local function timeStr(time) if time < 10 then return "0" .. tostring(time) else return tostring(time) end end local time = tonumber(obj:getLastMailbox("timeService")) local tempTime local timeH local timeM if time then if time < 0.5 then tempTime = 24 * time + 12 else tempTime = 24 * time - 12 end timeH = floor(tempTime) timeM = floor((tempTime - timeH) * 60) end electrics.values.time = (timeStr(timeH) .. ":" .. timeStr(timeM)) or ":"