OSRS Plugin API
    Preparing search index...

    Function subscribe

    • Subscribe to an event, returning an id that represents the callback that can be used in unsubscribe. Note that you cannot register the same callback twice on the same event.

      Parameters

      • callback: EventCallbackPolytype

        should be a function conforming to the appropriate callback signature for the event you are registering.

      • eventId: number

        should be one of the defined event id codes in the Events interface (e.g. POINTER_MOVE).

      Returns number

      callback id that can be used later to unsubscribe the event.

      -- Create a function
      local clock = 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,
      onValueChange = function()
      clockGoing = not clockGoing
      if clockGoing == false then
      osrs.print("Stop Clock")
      osrs.Events.unsubscribe(SubID)
      else
      osrs.print("Start Clock")
      SubID = osrs.Events.subscribe(clock, 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)