Skip to content

YaTimeComponent

Global singleton component for game time and timer events Developers can use the exposed method implementing delayed logics Use YaTime global object to access the APIs

Functions

TimeEventContainer WaitFor(number seconds)

ReturnsA container that hold the timer event
Wait for specified time and invoke a timer event (precision no lower than 0.1s)
  • seconds seconds to wait
1
2
3
EventHelper.AddListener(YaTime:WaitFor(10), "TimeEvent", function ()
    print("10 seconds elapsed")
end)

TimeEventContainer ScheduleAtInterval(number startSeconds, number intervalSeconds)

ReturnsA container that hold the timer event
Schedule a periodically invoked timer event (precision no lower than 0.1s)
  • startSeconds seconds to wait before the first timer event is invoked
  • intervalSeconds seconds to wait between two continuous timer event (this value must not be less than 0.1)
1
2
3
4
5
local counter = 0
EventHelper.AddListener(YaTime:ScheduleAtInterval(1, 1), "TimeEvent", function ()
    counter = counter + 1
    print("Counter value is now" .. counter)
end)