Skip to content

RegisterClientScript

Jérôme Leclercq edited this page Dec 8, 2020 · 1 revision

API: RegisterClientScript

Description:

Registers a script file that will be downloaded and used client-side.
Calling this function is required for every client script.

If no parameter is set, this function registers the script file from where it's called.

Prototype:

RegisterClientScript([filepath: string])

Parameters:

  1. filepath: Path to the script (relative to the scripts directory).

Remarks:

  1. All calls to RegisterClientScript should be done at initialization, before any player joins.
  2. Only server-registered scripts can be included client-side. If a client script tries to include a non-registered script file it will not be found by the game (independently of the file existence on the dive).
    The server and map editor don't have this restriction.
  3. This function exists client-side only for convenience and does nothing when called, as it's commonly called in shared element scripts.

Example code

A simple shared.lua entity using a custom asset

-- Registers the script client-side
RegisterClientScript()
-- Registers box.png as a client-side asset
RegisterClientAssets("box.png")

if (CLIENT) then
	entity:On("init", function (self)
		self:AddSprite({
			-- Using the asset
			TexturePath = "box.png"
		})
	end)
end

Clone this wiki locally