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.

Counter for a script.
#1
Hi there

For the past two hours I've been trying to declare a variable that would count how many times the LogiMachine has not reached the Internet.

If I don't declare the variable PingFailure, I get to following error message:

Resident script:17: attempt to perform arithmetic on local 'PingFailure' (a nil value)

If I do declare it, it never counts above 1 as it resets itself each time I carry out the script.  How is this done, I've searched this forum and the Internet?



function ping(ip)
  local res = os.execute('ping -c 2 -W 5 ' .. ip)
  return res == 0
end

local PingFailure = 0

ping = ping('google.com')

if ping then
  log('INTERNET connected')
  log(ping)
 
else
  log('INTERNET disconnected')
  log(ping)
  PingFailure = PingFailure + 1
end 

log(PingFailure)


I look forward to hearing from you.

Cheers!
Martin
Reply


Messages In This Thread
Counter for a script. - by kropfm - 11.08.2020, 11:46
RE: Counter for a script. - by Snoolik - 11.08.2020, 11:51
RE: Counter for a script. - by admin - 11.08.2020, 12:37
RE: Counter for a script. - by kropfm - 11.08.2020, 13:12
RE: Counter for a script. - by kropfm - 11.08.2020, 16:38

Forum Jump: