> For the complete documentation index, see [llms.txt](https://stigmax.gitbook.io/tfs-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stigmax.gitbook.io/tfs-guide/interface-globalevents/globalevent-scripting.md).

# Scripting

### Script Structure

> > #### *onStartup()*
> >
> > **Parameters**:
> >
> > * None
> >
> > **Return Value**:
> >
> > * **true**: Works as normal, no errors or prints to the console.
> > * **false**: Prints "Failed to execute event".
> >
> > **Example**:
> >
> > ```lua
> > function onStartup()
> >     print("Game server has started.")
> >     return true
> > end
> > ```
>
> > #### *onShutdown()*
> >
> > **Parameters**:
> >
> > * None
> >
> > **Return Value**:
> >
> > * None
> >
> > **Example**:
> >
> > ```lua
> > function onShutdown()
> >     for _, player in pairs(Game.getPlayers()) do
> >         -- Send FYI box, text messages won't go through before player is kicked
> >         player:popupFYI("Server is shutting down.")
> >     end
> > end
> > ```
> >
> > #### *onTime()*
> >
> > **Parameters**:
> >
> > * **time**: Time defined in XML.
> >
> > **Return Value**:
> >
> > * Follows same behavior as onStartup()
> >
> > **Example**:
> >
> > ```lua
> > -- <globalevent time="12:00" script="this_script.lua" />
> >
> > function onTime(time)
> >     print("Event is being executed at 12:00!")
> > end
> > ```
> >
> > #### *onThink(interval)*
> >
> > **Parameters**:
> >
> > * **interval**: Millisecond "think" interval defined in XML.
> >
> > **Return Value**:
> >
> > * Follows same behavior as onStartup()
> >
> > **Example**:
> >
> > ```lua
> > function onThink(interval)
> >     for _, player in pairs(Game.getPlayers()) do
> >         player:sendTextMessage(MESSAGE_INFO_DESCR, "Your name is " .. player:getName())
> >     end
> >     return true
> > end
> > ```
> >
> > #### *onRecord(current, old)*
> >
> > **Parameters**:
> >
> > * **current**: New player count record.
> > * **old**: Previous player count record.
> >
> > **Return Value**:
> >
> > * Follows same behavior as onStartup()
> >
> > **Example**:
> >
> > ```lua
> > function onRecord(current, old)
> >     Game.broadcastMessage("New player count record: " .. current)
> >     return true
> > end
> > ```
