the callback id returned from the subscribe method.
-- Create a function
local clockCallback = function()
osrs.print("Tick-Tock")
end
-- Subscribe to the function
local SubID = osrs.Events.subscribe(clock, osrs.Events.ON_GAME_TICK)
local clockGoing = true
-- Create new container
local newWindow = osrs.Ui.window({title = "Example Window"})
-- Create a UI checkbox that will subscribe and unsubscribe from the function
local clock = osrs.Ui.checkbox(
{
label = "Start/Stop Clock",
value = clockGoing,
changed = function()
clockGoing = not clockGoing
if clockGoing == false then
osrs.print("Stop Clcok")
osrs.Events.unsubscribe(SubID)
else
osrs.print("Start Clcok")
SubID = osrs.Events.subscribe(clockCallback, osrs.Events.ON_GAME_TICK)
end
end
}
)
-- Add the checkbox to the container
newWindow:addChild(clock)
-- Add the container to the canvas
osrs.Ui.canvas:addChild(newWindow)
the function that you wish to unsubscribe from the event.
-- Create a function
local clockCallback = function()
osrs.print("Tick-Tock")
end
-- Subscribe to the function
local SubID = osrs.Events.subscribe(clock, osrs.Events.ON_GAME_TICK)
local clockGoing = true
-- Create new container
local newWindow = osrs.Ui.window({title = "Example Window"})
-- Create a UI checkbox that will subscribe and unsubscribe from the function
local clock = osrs.Ui.checkbox(
{
label = "Start/Stop Clock",
value = clockGoing,
changed = function()
clockGoing = not clockGoing
if clockGoing == false then
osrs.print("Stop Clcok")
osrs.Events.unsubscribe(clockCallback)
else
osrs.print("Start Clcok")
SubID = osrs.Events.subscribe(clockCallback, osrs.Events.ON_GAME_TICK)
end
end
}
)
-- Add the checkbox to the container
newWindow:addChild(clock)
-- Add the container to the canvas
osrs.Ui.canvas:addChild(newWindow)
Unsubscribes a callback from an event.