Page 2 of 2
Re: Issues with weather in Command
Posted: Wed Oct 08, 2025 2:49 pm
by thewood1
Again, the custom zone will manage the conflict, if one exists. The CZs have full lua support and setting a CZ's temp will completely override any global temp in that region.
Re: Issues with weather in Command
Posted: Wed Oct 08, 2025 4:58 pm
by thewood1
Re: Issues with weather in Command
Posted: Wed Oct 08, 2025 5:28 pm
by Uzabit
@Nikel
Here's a corrected code snippet for the temperature simulation script you posted. I should now work as I just tested it in a scenario. It still counteracts the internal temperature engine of CMO. So I'm not sure how useful it is.
Code: Select all
-- Daily temperature simulation script (Command: Modern Operations)
local baseTemp = 15 -- Average temperature (°C)
local amplitude = 5 -- Half of the total daily range (°C)
local peakHour = 15 -- Hour of peak temperature (3 PM)
-- Get current scenario time and extract the hour (00–23)
local scenTime = ScenEdit_CurrentTime()
local hour
if type(scenTime) == "string" then
-- Expected format: "YYYY-MM-DD HH:MM:SS"
hour = tonumber(string.sub(scenTime, 12, 13))
else
-- Fallback if an epoch-like number is returned
hour = tonumber(os.date("!%H", scenTime))
end
-- Calculate smooth daily temperature curve
-- Use cosine so the maximum occurs at 'peakHour'
local pi = math.pi
local temp = baseTemp + amplitude * math.cos((2 * pi / 24) * (hour - peakHour))
-- Get current global weather (fields: temp, rainfall, undercloud, seastate)
local w = ScenEdit_GetWeather()
-- Apply new temperature while preserving rainfall, cloud cover, and sea state
local ok = ScenEdit_SetWeather(temp, w.rainfall, w.undercloud, w.seastate)
-- Optional: log the update to console
if ok then
print(string.format(
"Hour: %02d | Temp set to: %.2f°C | Rainfall: %.1f | Undercloud: %.2f | SeaState: %d",
hour, temp, w.rainfall, w.undercloud, w.seastate
))
else
print("ScenEdit_SetWeather failed.")
end
*Edit* Replaced math.sin() with math.cos() to ensure the temperature peak aligns correctly with peakHour (15:00).