Jump to content

Again weather system


Recommended Posts

Posted

Error:Line 23 : attemt to index local 'weather' (a nil value)

local weatherTable={            
    { weatherid=0, name="Nagyon meleg"},
    { weatherid=1, name="Meleg"},
    { weatherid=2, name="Napos, kissé ködös"},
    { weatherid=9, name="Ködös"},
}

local currentWeatherTable={}
function setNewWeather()
    while (#currentWeatherTable<7) do
        table.insert(currentWeatherTable,weatherTable[math.random(1,#weatherTable)])
    end
end

function weatherSystemStart()
    setWeather(1)
end
addEventHandler("onResourceStart", resourceRoot,setNewWeather)
addEventHandler("onResourceStart", resourceRoot,weatherSystemStart)

function newWeather()
    local weather=table.remove(currentWeatherTable,1)
    outputChatBox("The Weather changes. ("..weather.name..")",root,255,255,255,true)
    setWeather(weather.weatherid)
end
setTimer(newWeather,360,0)

Whats the problem?

Posted

When changing the weather, randomly get this erro: Error:Line 23 : attemt to index local 'weather' (a nil value) then the timer dead. Need to restart. After some time again error, then need restart..

  • Moderators
Posted
if #currentWeatherTable == 0 then
  setNewWeather()
end

Place between line 21 and 22. (in the current code here)

Which will full up the 'currentWeatherTable' table again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...