[MIRROR] Fixes lua error logging and a few timer.lua functions (#26999)

Fixes lua error logging and a few timer.lua functions (#82160)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->
Lua errors don't get logged when `call_function` is called

Timer.start_loop was just straight up broken due to me not properly
testing it, so this fixes that.

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->
Makes debugging lua scripts easier. Also fixes bugs.

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
fix: Fixed lua error logging.
fix: Fixed the SS13.start_loop function not working properly.
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
Co-authored-by: Useroth <37159550+Useroth@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-04-03 02:05:53 +02:00
committed by GitHub
parent daa5315bd1
commit d9618abbdf
2 changed files with 21 additions and 16 deletions
+17 -14
View File
@@ -24,11 +24,13 @@ end
function __stop_internal_timer(func)
local timer = __Timer_timers[func]
if timer and not timer.executing then
__Timer_timers[func] = nil
__Timer_callbacks[func] = nil
else
timer.terminate = true
if timer then
if not timer.executing then
__Timer_timers[func] = nil
__Timer_callbacks[func] = nil
else
timer.terminate = true
end
end
end
@@ -36,7 +38,7 @@ __Timer_timer_processing = __Timer_timer_processing or false
SS13.state:set_var("timer_enabled", 1)
__Timer_timer_process = function(seconds_per_tick)
if __Timer_timer_processing then
return
return 0
end
__Timer_timer_processing = true
local time = dm.world:get_var("time")
@@ -53,6 +55,7 @@ __Timer_timer_process = function(seconds_per_tick)
end
end
__Timer_timer_processing = false
return 1
end
function Timer.wait(time)
@@ -77,18 +80,18 @@ function Timer.start_loop(time, amount, func)
if amount == 1 then
return __add_internal_timer(func, time * 10, false)
end
local callback = SS13.new("/datum/callback", SS13.state, "call_function")
local timedevent = dm.global_proc("_addtimer", callback, time * 10, 40, nil, debug.info(1, "sl"))
local doneAmount = 0
-- Lua counts from 1 so let's keep consistent with that
local doneAmount = 1
local funcId
local newFunc = function()
func()
func(doneAmount)
doneAmount += 1
if doneAmount >= amount then
Timer.end_loop(timedevent)
if doneAmount > amount then
Timer.end_loop(funcId)
end
end
__add_internal_timer(newFunc, time * 10, true)
return newFunc
funcId = __add_internal_timer(newFunc, time * 10, true)
return funcId
end
function Timer.end_loop(id)