# Method WorldObject:RegisterEvent [-] [+]

Registers a timed event to the WorldObject When the passed function is called, the parameters `(eventId, delay, repeats, worldobject)` are passed to it. Repeats will decrease on each call if the event does not repeat indefinitely

Note that for Creature and GameObject the timed event timer ticks only if the creature is in sight of someone For all WorldObjects the timed events are removed when the object is destoryed. This means that for example a Player's events are removed on logout.

    local function Timed(eventid, delay, repeats, worldobject)
        print(worldobject:GetName())
    end
    worldobject:RegisterEvent(Timed, 1000, 5) -- do it after 1 second 5 times
    worldobject:RegisterEvent(Timed, {1000, 10000}, 0) -- do it after 1 to 10 seconds forever

In multistate, this method is only available in the MAP states

## Synopsis

`eventId = WorldObject:RegisterEvent( function, delay )`

`eventId = WorldObject:RegisterEvent( function, delaytable )`

`eventId = WorldObject:RegisterEvent( function, delay, repeats )`

`eventId = WorldObject:RegisterEvent( function, delaytable, repeats )`

## Arguments

`function function`

  Function to trigger when the time has passed.

`number delay`

  Set time in milliseconds for the event to trigger.

  Valid numbers: integers from 0 to 4,294,967,295.

`table delaytable`

  A table `{min, max}` containing the minimum and maximum delay time.

`number repeats (1)`

  How many times for the event to repeat, 0 is infinite.

  Valid numbers: integers from 0 to 4,294,967,295.

## Returns

`number eventId`

  Unique ID for the timed event used to cancel it or nil.

  Valid numbers: integers from -2,147,483,647 to 2,147,483,647.

# Keyboard shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

# Search tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct` (or `str`), `enum`, `trait`, `typedef` (or `tdef`).

Generated on
© 2010 - 2024 Eluna Lua Engine