Client Loader¶
If you want to override the default main client script, this section will be helpful. The ClientLoader
object is what controls the whole crosswalk lifecycle: it will load the given modules, connect to remotes sent from the server and run special functions.
Overriding the Default Entrypoint¶
Although it may seem like an obvious step, make sure that you are not using the default provided ClientMain script.
- Create a new entrypoint to initialize crosswalk. Insert a LocalScript in ReplicatedFirst or StarterPlayerScripts for example.
- In that script, require the
ClientLoader
class. - Create a new object of that class using the
new
constructor. It should look likelocal loader = ClientLoader.new({ ... })
. Three list should be provided to the constructor, one for each kind of modules (server, client and shared). - Call the
start
method.
Overall, it should be similar to this:
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ClientLoader = require(ReplicatedStorage:WaitForChild('ClientLoader'))
local loader = ClientLoader.new({
clientModules = ReplicatedStorage:WaitForChild('ClientModules'):GetChildren(),
sharedModules = ReplicatedStorage:WaitForChild('SharedModules'):GetChildren(),
-- put other configuration values to override:
-- to provide modules that are not going to get linked and connected by
-- crosswalk, use `externalModules`
externalModules = {
Llama = require(ReplicatedStorage:WaitForChild('Llama')),
Roact = require(ReplicatedStorage:WaitForChild('Roact')),
},
-- this will make crosswalk print a bunch of information to the output
logLevel = 'debug',
})
loader:start()
API¶
Constructor¶
To construct a new ClientLoader
object, call the new
function:
ClientLoader.new(configuration)
The configuration
parameter is a table that contains the values presented here.
field | type | description |
---|---|---|
clientModules | ModuleScript list | a list of client modules to load |
sharedModules | ModuleScript list | a list of shared modules to load |
externalModules | { [string]: any } | a dictionary that maps a module name to its implementation |
logLevel | 'error' , 'warn' , 'info' or 'debug' | Defines what will crosswalk's reporter outputs to the console. Default is 'warn' |
customModuleFilter | (ModuleScript) -> boolean (optional) | Provide a function to filter modules that are not regular crosswwalk modules. crosswalk will not automatically call Init , Start , OnPlayerReady or OnPlayerLeaving functions on these modules. Defaults to a filter that selects ModuleScript with names ending with Class |
excludeModuleFilter | (ModuleScript) -> boolean (optional) | Provide a function that excludes ModuleScripts from loading at all. Defaults to a filter that removes ModuleScript with names ending with .spec or .test |
start
¶
To initialize crosswalk on the client side, call the start
method on the ClientLoader
object:
-- first, create a new object
local clientLoader = ClientLoader.new({
clientModules = ReplicatedStorage.ClientModules:GetChildren(),
sharedModules = ReplicatedStorage.SharedModules:GetChildren(),
logLevel = 'warn',
})
-- start crosswalk!
clientLoader:start()