Is there a way to stop minetest.register_globalstep?

Post Reply
User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Is there a way to stop minetest.register_globalstep?

by Andrey01 » Post

Is there a way to stop minetest.register_globalstep call? It is infinte?

User avatar
ChimneySwift
Member
Posts: 320
Joined: Fri Sep 22, 2017 06:46
GitHub: ChimneySwift
IRC: ChimneySwift
In-game: ChimneySwift
Location: 127.0.0.1

Re: Is there a way to stop minetest.register_globalstep?

by ChimneySwift » Post

Are you talking about a way to stop callbacks registered from other mods? Or by your own mod? If by your own mod it should be fairly simple:

Code: Select all

runner = true

time = 0
minetest.register_globalstep(function(dtime)
    time = time + dtime

    if time >= 10 then
        runner = false
    end

    if runner then 
        -- do stuff
    end
end)
This will run the globalstep for 10 seconds (approx. 100 iterations) then stop.
A spoon is basically a tiny bowl with a stick on it

User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Is there a way to stop minetest.register_globalstep?

by Andrey01 » Post

Thanks, ChimneySwift. That i needed.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Is there a way to stop minetest.register_globalstep?

by sofar » Post

it's slightly more efficient to use `minetest.after()` if you do not need to run lua code every globalstep.

Code: Select all

local function work()
    minetest.after(10, work) -- once every 10 seconds
    -- do something
    print("work done")
end
minetest.after(10, work)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests