This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

openweather ONE call API
#21
Do you have snowsum = 0 before the repeat loop? What is the exact error that you get?
Reply
#22
(15.01.2024, 10:26)admin Wrote: Do you have snowsum = 0 before the repeat loop? What is the exact error that you get?

Yes i and snowsum is initialized before.

I getting the fault:

Code:
User script:83: attempt to index field 'snow' (a nil value)
stack traceback:
Reply
#23
Try this:
Code:
snowsum = 0

for i = 1, 24 do
  hourly = data.hourly[i]

  if hourly.snow then
    snowsum = snowsum + (hourly.snow['1h'] or 0)
  end
end
Reply
#24
(15.01.2024, 10:32)admin Wrote: Try this:
Code:
snowsum = 0

for i = 1, 24 do
  hourly = data.hourly[i]

  if hourly.snow then
    snowsum = snowsum + (hourly.snow['1h'] or 0)
  end
end

Many thanks this is working!  Smile
Reply


Forum Jump: