Skip to main content

sm

The sm namespace contains all API features related to Scrap Mechanic.

Constants

isHost

sm.isHost = <boolean>

A boolean value indicating whether the current game instance is hosting the world or not.
If false, the game instance is a client in a multiplayer session.


version

sm.version = "0.7.4.778"

A string value containing the current version of the game.


Functions

exists

local exists = sm.exists(value)

Checks whether the given value "exists" in the game.

If the given value is a basic Lua type, this simply returns true if the value is non-nil.

If the value is a reference userdata however, this function checks if the actual, underlying engine object (e.g. a referenced Shape) still exists in the game.
This is useful to avoid calling API functions on already-destroyed objects (which would throw a script error).

Parameters:

  • value (any): The value to check.

Returns:

  • exists (boolean): Whether the given value "exists" or not.

isServerMode

local isServerContext = sm.isServerMode()

Returns whether the calling function is currently being executed in server context.
If this is false, the function is executing in client context.
Server context only occurs when sm.isHost is true.

Returns:

  • isServerContext (boolean): Whether the script is executing in server context or not.