H! I have a problem while creating a Fivem Script that calculates temperature according to the month and a random generator. When i ensure the script in the Fivem server, i have an error.
CODE:
local temperature
local monthNumberR
local monthStringG
local mustSnow
local probTempHigh
local probTempLow
local showTemperature = true
local displayY
Citizen.CreateThread(function()
while true do
Wait(1)
if showTemperature == true then
CalculateTemperature()
displayY = temperature.."°C"
end
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.40, 0.40)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextRightJustify(true)
SetTextWrap(0,0.95)
SetTextEntry("STRING")
AddTextComponentString(displayY)
DrawText(0.5, 0.01)
end
end)
function CalculateTemperature()
monthNumberR = getClockMonth()
--MONTH STRING CONVERTER
if monthNumberR == 0 then
monthStringG = "JAN"
elseif monthNumberR == 1 then
monthStringG = "FEB"
elseif monthNumberR == 2 then
monthStringG = "MAR"
elseif monthNumberR == 3 then
monthStringG = "APR"
elseif monthNumberR == 4 then
monthStringG = "MAY"
elseif monthNumberR == 5 then
monthStringG = "JUN"
elseif monthNumberR == 6 then
monthStringG = "JUL"
elseif monthNumberR == 7 then
monthStringG = "AUG"
elseif monthNumberR == 8 then
monthStringG = "SEP"
elseif monthNumberR == 9 then
monthStringG = "OCT"
elseif monthNumberR == 10 then
monthStringG = "NOV"
elseif monthNumberR == 11 then
monthStringG = "DEC"
end
--MONTH PROB TEMP HIGH/LOW CALCULATOR
if monthStringG == "DEC" or monthStringG == "GEN" or monthStringG == "FEB" then
probTempHigh = 3
probTempLow = 97
else if monthStringG == "MAR" or monthStringG == "APR" or monthStringG == "MAY" then
probTempHigh = 20
probTempLow = 80
else if monthStringG == "JUN" or monthStringG == "JUL" then
probTempHigh = 95
probTempLow = 5
else if monthStringG == "AUG" then
probTempHigh = 70
probTempLow = 30
else if monthStringG == "SEP" then
probTempHigh = 50
probTempLow = 50
else if monthStringG == "OCT" then
probTempHigh = 40
probTempLow = 60
else if monthStringG == "NOV" then
probTempHigh = 30
probtempLow = 70
end
--TEMPERATURE CALCULATOR
local random = math.random(0,100)
local random2 = math.random(0,100)
local random3SNOW = math.random(0,100)
if random <= probTempHigh then
if probTempHigh <= 10 then
temperature = math.random(22,26)
else if probTempHigh <= 30 then
temperature = math.random(27,29)
else if probTempHigh <= 70 then
if random2 <= 50 then
temperature = math.random(30,33)
else
temperature = math.random(22,30)
end
else
if random2 <=50 then
temperature = math.random(33,35)
else
temperature = math.random(36,40)
end
end
else
if probTempLow <= 10 then
temperature = math.random(16,22)
else if probTempLow <= 30 then
temperature = math.random(13,16)
else if probTempLow <= 70 then
if random2 <= 50 then
temperature = math.random(9,13)
else
temperature = math.random(7,9)
else
if random2 <=50 then
temperature = math.random(5,7)
else
temperature = math.random(0,5)
--SNOW CALCULATOR
if random3SNOW <= 50 then
mustSnow = true
else
mustSnow = false
end
end
end
end
end
--UTILITIES
function textNotify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
I modified a little the code but now i have this error:
Error parsing script @SeasonScript/client/temperature.lua in resource @SeasonScript/client/temperature.lua:115: 'end' expected (to close 'if' at line 100) near else
but the if is closed at line 139.
The code is:
local temperature
local monthNumberR
local monthStringG
local mustSnow
local probTempHigh
local probTempLow
local showTemperature = true
local displayY
Citizen.CreateThread(function()
while true do
Wait(1)
if showTemperature == true then
CalculateTemperature()
displayY = temperature.."°C"
end
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.40, 0.40)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextRightJustify(true)
SetTextWrap(0,0.95)
SetTextEntry("STRING")
AddTextComponentString(displayY)
DrawText(0.5, 0.01)
textNotify(displaY)
end
end)
function CalculateTemperature()
monthNumberR = getClockMonth()
--MONTH STRING CONVERTER
if monthNumberR == 0 then
monthStringG = "JAN"
elseif monthNumberR == 1 then
monthStringG = "FEB"
elseif monthNumberR == 2 then
monthStringG = "MAR"
elseif monthNumberR == 3 then
monthStringG = "APR"
elseif monthNumberR == 4 then
monthStringG = "MAY"
elseif monthNumberR == 5 then
monthStringG = "JUN"
elseif monthNumberR == 6 then
monthStringG = "JUL"
elseif monthNumberR == 7 then
monthStringG = "AUG"
elseif monthNumberR == 8 then
monthStringG = "SEP"
elseif monthNumberR == 9 then
monthStringG = "OCT"
elseif monthNumberR == 10 then
monthStringG = "NOV"
elseif monthNumberR == 11 then
monthStringG = "DEC"
end
--MONTH PROB TEMP HIGH/LOW CALCULATOR
if monthString == "DEC" or monthString == "GEN" or monthString == "FEB" then
probTempHigh = 3
probTempLow = 97
else if monthString == "MAR" or monthString == "APR" or monthString == "MAY" then
probTempHigh = 20
probTempLow = 80
else if monthString == "JUN" or monthString == "JUL" then
probTempHigh = 95
probTempLow = 5
else if monthString == "AUG" then
probTempHigh = 70
probTempLow = 30
else if monthString == "SEP" then
probTempHigh = 50
probTempLow = 50
else if monthString == "OCT" then
probTempHigh = 40
probTempLow = 60
else if monthString == "NOV" then
probTempHigh = 30
probtempLow = 70
end
--TEMPERATURE CALCULATOR
local random = math.random(0,100)
local random2 = math.random(0,100)
local random3SNOW = math.random(0,100)
if random <= probTempHigh then
if probTempHigh <= 10 then
temperature = math.random(22,26)
else if probTempHigh <= 30 then
temperature = math.random(27,29)
else if probTempHigh <= 70 then
if random2 <= 50 then
temperature = math.random(30,33)
else
temperature = math.random(22,30)
end
else
if random2 <=50 then
temperature = math.random(33,35)
else
temperature = math.random(36,40)
end
end
else
if probTempLow <= 10 then
temperature = math.random(16,22)
else if probTempLow <= 30 then
temperature = math.random(13,16)
else if probTempLow <= 70 then
if random2 <= 50 then
temperature = math.random(9,13)
else
temperature = math.random(7,9)
else
if random2 <=50 then
temperature = math.random(5,7)
else
temperature = math.random(0,5)
--SNOW CALCULATOR
if random3SNOW <= 50 then
mustSnow = true
else
mustSnow = false
end
end
end
end
end
--UTILITIES
function textNotify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
SCRIPT ERROR: @SeasonScript/client/temperature.lua:39: attempt to call a nil value (global 'getClockMonth')
fn (@SeasonScript/client/temperature.lua:15)
At first I initialize it with local probTempHigh, then I assign it to a numeric value between 0 and 100 (e.g. probTempHigh = 3) and then I do that if
CODE:
local temperature
local monthNumberR
local monthStringG
local mustSnow
local probTempHigh
local probTempLow
local showTemperature = true
local displayY
Citizen.CreateThread(function()
while true do
Wait(1)
if showTemperature == true then
CalculateTemperature()
displayY = temperature.."°C"
end
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.40, 0.40)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextRightJustify(true)
SetTextWrap(0,0.95)
SetTextEntry("STRING")
AddTextComponentString(displayY)
DrawText(0.5, 0.01)
textNotify(displaY)
end
end)
function CalculateTemperature()
monthNumberR = GetClockMonth()
--MONTH STRING CONVERTER
if monthNumberR == 0 then
monthStringG = "JAN"
elseif monthNumberR == 1 then
monthStringG = "FEB"
elseif monthNumberR == 2 then
monthStringG = "MAR"
elseif monthNumberR == 3 then
monthStringG = "APR"
elseif monthNumberR == 4 then
monthStringG = "MAY"
elseif monthNumberR == 5 then
monthStringG = "JUN"
elseif monthNumberR == 6 then
monthStringG = "JUL"
elseif monthNumberR == 7 then
monthStringG = "AUG"
elseif monthNumberR == 8 then
monthStringG = "SEP"
elseif monthNumberR == 9 then
monthStringG = "OCT"
elseif monthNumberR == 10 then
monthStringG = "NOV"
elseif monthNumberR == 11 then
monthStringG = "DEC"
end
--MONTH PROB TEMP HIGH/LOW CALCULATOR
if monthString == "DEC" or monthString == "GEN" or monthString == "FEB" then
probTempHigh = 3
probTempLow = 97
elseif monthString == "MAR" or monthString == "APR" or monthString == "MAY" then
probTempHigh = 20
probTempLow = 80
elseif monthString == "JUN" or monthString == "JUL" then
probTempHigh = 95
probTempLow = 5
elseif monthString == "AUG" then
probTempHigh = 70
probTempLow = 30
elseif monthString == "SEP" then
probTempHigh = 50
probTempLow = 50
elseif monthString == "OCT" then
probTempHigh = 40
probTempLow = 60
elseif monthString == "NOV" then
probTempHigh = 30
probtempLow = 70
end
--TEMPERATURE CALCULATOR
local random = math.random(0,100)
local random2 = math.random(0,100)
local random3SNOW = math.random(0,100)
if random <= probTempHigh then
if probTempHigh <= 10 then
temperature = math.random(22,26)
elseif probTempHigh <= 30 then
temperature = math.random(27,29)
elseif probTempHigh <= 70 then
if random2 <= 50 then
temperature = math.random(30,33)
else
temperature = math.random(22,30)
end
else
if random2 <=50 then
temperature = math.random(33,35)
else
temperature = math.random(36,40)
end
end
else
if probTempLow <= 10 then
temperature = math.random(16,22)
elseif probTempLow <= 30 then
temperature = math.random(13,16)
elseif probTempLow <= 70 then
if random2 <= 50 then
temperature = math.random(9,13)
else
temperature = math.random(7,9)
end
else
if random2 <=50 then
temperature = math.random(5,7)
else
temperature = math.random(0,5)
--SNOW CALCULATOR
if random3SNOW <= 50 then
mustSnow = true
else
mustSnow = false
end
end
end
end
end
--UTILITIES
function textNotify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
textNotify("probTempHigh:"..tostring(probTempHigh))
textNotify("probTempLow:"..tostring(probTempLow))
function textNotify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
and now it prints
probTempHigh:nil
probTempLow:nil
EDIT:
I modified the initialization of the variables,