timer with luacontroller

User avatar
Serh Arien
Member
 
Posts: 68
Joined: Tue Nov 03, 2015 19:53

timer with luacontroller

by Serh Arien » Sat May 14, 2016 23:16

Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Someone prupose me this code but it's no work :
Code: Select all
    Interrupt(1) --executes the programm every second
    if (event.type == "on" and event.pin.name == "A") then --if signal at A
       port.b = true --start counting and show it
    elseif (event.type == "interrupt" and port.b) then
       if (not mem.counter) then
         mem.counter = 0 --init
       end
       if (mem.counter == 120) then --if reaching 120 seconds
          port.b = false   --stop counter
          port.c = true     --send final signal
       else
          mem.counter = mem.counter + 1 --count up
       end
    end


Does someone know more than me about codding and can tell me the right code ( if it's possible)

Thank you
 

User avatar
Krock
Developer
 
Posts: 4408
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: timer with luacontroller

by Krock » Mon May 16, 2016 07:16

Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Serh Arien
Member
 
Posts: 68
Joined: Tue Nov 03, 2015 19:53

Re: timer with luacontroller

by Serh Arien » Mon May 16, 2016 15:23

Krock wrote:
Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end


Meaning ? Have i to change something on the code? Add or delete things
 

User avatar
Krock
Developer
 
Posts: 4408
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: timer with luacontroller

by Krock » Mon May 16, 2016 15:34

Serh Arien wrote:Meaning ? Have i to change something on the code? Add or delete things

Use that code as a replacement of what you posted for your luacontroller. If you don't want to wait two minutes, simply decrease the time delay argument of the minetest.after function from 120 to 10. Hopefully it works.

EDIT: port.c won't be turned off again after the delay. You need to extend the code to turn it off after one second or more.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
yyt16384
Member
 
Posts: 46
Joined: Mon Nov 03, 2014 12:16
Location: China
GitHub: yyt16384
IRC: yyt16384
In-game: yyt16384

Re: timer with luacontroller

by yyt16384 » Mon May 16, 2016 16:12

Krock wrote:
Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end


I don't think you can use minetest.after in luacontrollers.
 

User avatar
Serh Arien
Member
 
Posts: 68
Joined: Tue Nov 03, 2015 19:53

Re: timer with luacontroller

by Serh Arien » Mon May 16, 2016 19:16

Krock wrote:
Serh Arien wrote:Meaning ? Have i to change something on the code? Add or delete things

Use that code as a replacement of what you posted for your luacontroller. If you don't want to wait two minutes, simply decrease the time delay argument of the minetest.after function from 120 to 10. Hopefully it works.

EDIT: port.c won't be turned off again after the delay. You need to extend the code to turn it off after one second or more.


It's no working, i think the port a is not open because there is no light on it
How can i fix it ?

I know, this is a mesecon website where it's explain but codding and me = level -100000 :D
 

cheapie
Member
 
Posts: 315
Joined: Mon May 14, 2012 00:59
GitHub: cheapie
IRC: cheapie
In-game: cheapie

Re: timer with luacontroller

by cheapie » Mon May 16, 2016 19:40

This will make the LuaC act like a delayer with any length you want. Input is pin A and output is C, change the first line to adjust the time.

Code: Select all
local time = 120
if (event.type == "on" or event.type == "off") and event.pin.name == "A" then
   if event.type == "on" then
      interrupt(time,"on")
   elseif event.type == "off" then
      interrupt(time,"off")
   end
elseif event.type == "interrupt" then
   if event.iid == "on" then
      port.c = true
   elseif event.iid == "off" then
      port.c = false
   end
end
 

User avatar
Serh Arien
Member
 
Posts: 68
Joined: Tue Nov 03, 2015 19:53

Re: timer with luacontroller

by Serh Arien » Mon May 16, 2016 20:02

cheapie wrote:This will make the LuaC act like a delayer with any length you want. Input is pin A and output is C, change the first line to adjust the time.

Code: Select all
local time = 120
if (event.type == "on" or event.type == "off") and event.pin.name == "A" then
   if event.type == "on" then
      interrupt(time,"on")
   elseif event.type == "off" then
      interrupt(time,"off")
   end
elseif event.type == "interrupt" then
   if event.iid == "on" then
      port.c = true
   elseif event.iid == "off" then
      port.c = false
   end
end


OMG it's work ! Thank you, you helped me more than you think
 


Return to General Discussion



Who is online

Users browsing this forum: No registered users and 4 guests