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.

Problem with require
#1
Hi,

I have a problem with a library. I don´t know how exactly works require but a function doesn´t work sometimes.

In my library user.Varios I have a function like this:

Code:
local TemporizadoresActivos = {   {       {Nombre = "ACK_Temp_Extractor_Aseo", Input = "1/1/115", Output = "1/1/15", Tiempo = "0/3/31", DG_Tempo_Activo = "34/6/1", DG_Tempo = "34/6/101", Condicion = '3/4/141', ACKCondicion = '3/4/41', T_Activo = false},   },   {   },  } function Revisar_Temporizadores ()     now = os.time()     for i = 1,#TemporizadoresActivos, 1 do         local tf = "_on"         if i == 2 then tf = "_off" end         for _, pir in ipairs(TemporizadoresActivos[i]) do             if next(pir) then                 --log(pir)                 key = 'pir_timer_' .. pir.Input .. tf                 delta = now - storage.get(key, 0)                 if grp.getvalue(pir.DG_Tempo_Activo) and pir.T_Activo then                     grp.checkupdate(pir.DG_Tempo,delta)                 end                 t = grp.getvalue(pir.Tiempo)*60                 if pir.Condicion == nil then                     if delta > t then                         if pir.Output ~= nil then                             grp.checkwrite(pir.Output, 0)                         end                         grp.checkupdate(pir.DG_Tempo_Activo,false)                     end                 end             end          end    -     end end

And from resident script (15seg) I call this function

Code:
require('user.Varios') local Revisar_Temporizadores ()


But sometimes objects doesn´t update and when I save again resident script they update correctly. I don´t change nothing in function only save again.

Why does this happend?

Thanks
Reply
#2
Check Error log entries. The scripts you've posted are incorrect. There's "-" sign in line 31 of the library and local Revisar_Temporizadores () is not valid syntax.
Reply
#3
Sorry... I change some parts to reduce the code and I put wrong...
No mistakes in syntax and no mistakes in error log

This is the original code in user.varios
Code:
function Revisar_Temporizadores ()   now = os.time()   for i = 1,#TemporizadoresActivos, 1 do   local tf = "_on"   if i == 2 then tf = "_off" end       for _, pir in ipairs(TemporizadoresActivos[i]) do         if next(pir) then           --log(pir)           CrearDG ("ACK_Temp_"..pir.Nombre, pir.DG_Tempo_Activo, dt.bool,"ACK_Tiempo_Activo")           CrearDG ("Delta_"..pir.Nombre, pir.DG_Tempo, dt.uint32)           key = 'pir_timer_' .. pir.Input .. tf           delta = now - storage.get(key, 0)           if grp.getvalue(pir.DG_Tempo_Activo) and pir.T_Activo then             grp.checkupdate(pir.DG_Tempo,delta)           end           t = grp.getvalue(pir.Tiempo)*60           if pir.Condicion == nil then             if delta > t then               if pir.Output ~= nil then                 grp.checkwrite(pir.Output, 0)               end               grp.checkupdate(pir.DG_Tempo_Activo,false)             end           else             local cumple = (grp.getvalue(pir.Condicion) - 200) > grp.getvalue(pir.ACKCondicion)             if (delta > t) and (cumple) then               grp.checkwrite(pir.Output, 0)               grp.checkupdate(pir.DG_Tempo_Activo,false)             elseif (delta > t) and (not cumple) and ((grp.getvalue(pir.DG_Tempo_Activo))) then               storage.set(key, now)             end                      end             end     end    --End for temporizadores on off   end --End for temporizadores   return ("Temporizadores Revisados") end --End funcion


And this in resident

Code:
require('user.Varios') local Revisados = Revisar_Temporizadores ()
Reply
#4
Add some extra log() calls to your script to check where a logic error might be.
Reply


Forum Jump: