Weather Event Not Working
Posted: Tue Jun 23, 2020 8:05 pm
I am trying to use the following code to modify the weather. Basic operation is that there is an equal chance the weather will worsen, improve or stay the same. This code is hanging up on the temperature value as every time it returns a value of 'nil' for temperature even if I use the "tonumber" operator. Any ideas on why this doesn't work?
math.randomseed(os.time())
math.random();
math.random(); math.random()
local w=ScenEdit_GetWeather()
local c=math.random(1,3)
if c==1 then
local newtemp=tonumber(w.temperature) - math.random(3,8)
local newrain=tonumber(w.rainfall) + math.random(10,30)
if newrain>>50 then
newrain= 50
end
local newcloud=tonumber(w.undercloud) + math.random(1,3)
if newcloud>>1 then
newcloud=1
end
local newstate=tonumber(w.seastate)+math.random(1,3)
if newstate>>9 then
newstate=9
end
ScenEdit_SetWeather(newtemp, newrain, newcloud, newstate)
elseif c==2 then
local newtemp=tonumber(w.temperature) + math.random(3,8)
local newrain=tonumber(w.rainfall) - math.random(10,30)
if newrain<<0 then
newrain= 0
end
local newcloud=tonumber(w.undercloud) - math.random(1,3)
if newcloud<<0 then
newcloud=0
end
local newstate=tonumber(w.seastate)-math.random(1,3)
if newstate<<0 then
newstate=0
end
ScenEdit_SetWeather(newtemp, newrain, newcloud, newstate)
else
return
end
math.randomseed(os.time())
math.random();
math.random(); math.random()
local w=ScenEdit_GetWeather()
local c=math.random(1,3)
if c==1 then
local newtemp=tonumber(w.temperature) - math.random(3,8)
local newrain=tonumber(w.rainfall) + math.random(10,30)
if newrain>>50 then
newrain= 50
end
local newcloud=tonumber(w.undercloud) + math.random(1,3)
if newcloud>>1 then
newcloud=1
end
local newstate=tonumber(w.seastate)+math.random(1,3)
if newstate>>9 then
newstate=9
end
ScenEdit_SetWeather(newtemp, newrain, newcloud, newstate)
elseif c==2 then
local newtemp=tonumber(w.temperature) + math.random(3,8)
local newrain=tonumber(w.rainfall) - math.random(10,30)
if newrain<<0 then
newrain= 0
end
local newcloud=tonumber(w.undercloud) - math.random(1,3)
if newcloud<<0 then
newcloud=0
end
local newstate=tonumber(w.seastate)-math.random(1,3)
if newstate<<0 then
newstate=0
end
ScenEdit_SetWeather(newtemp, newrain, newcloud, newstate)
else
return
end