Logic Machine Forum
openweather ONE call API - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: openweather ONE call API (/showthread.php?tid=3623)

Pages: 1 2


RE: openweather ONE call API - admin - 15.01.2024

Do you have snowsum = 0 before the repeat loop? What is the exact error that you get?


RE: openweather ONE call API - pioneersteffen - 15.01.2024

(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:



RE: openweather ONE call API - admin - 15.01.2024

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



RE: openweather ONE call API - pioneersteffen - 15.01.2024

(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