Packages
Runtime

Runtime

Runtime is a simple wally package that helps to "initialize" core game modules. Ideally helping to cut down the "loader" script size and improve the look of the loader script.

This package was inspired by sleitnicks 'Loader' class, please go check it out!

Properties

Methods

RequireChildren

Runtime:RequireChildren( parent Instance (opens in a new tab), middlewareFn (module: ModuleScript, content: { [any]: any }) -> { [any]: any } ) -> { { [any]: any } }

A simple function that will iterate over a "Parent" instance's children and require all modules. This module will then return an array, containing the result of each require call

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
 
	Runtime:RequireChildren(script.Parent.Controllers, function(module: ModuleScript, moduleContent: { [any]: any })
		print(`Loaded module '{module.Name}'`)
 
		return moduleContent
	end)

RequireDescendants

Runtime:RequireDescendants( parent Instance (opens in a new tab), middlewareFn (module: ModuleScript, content: { [any]: any }) -> { [any]: any } ) -> { { [any]: any } }

A simple function that will iterate over a "Parent" instance's descendants and require all modules. This module will then return an array, containing the result of each require call

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
 
	Runtime:RequireDescendants(script.Parent, function(module: ModuleScript, moduleContent: { [any]: any })
		print(`Loaded module '{module.Name}'`)
 
		return moduleContent
	end)

CallMethodOn

Runtime:CallMethodOn( modules { { [any]: any } }, methodName string (opens in a new tab), arguments ... ) -> nil (opens in a new tab)

A simple function that will call a method on an array of tables. Useful when used in combination with RequireDescendants/RequireChildren calls.

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
	
	local gameConstants = {
		...
	}
 
	-- require all modules under the 'Controllers' instance, call 'OnInit'
	-- function in each module, if it exists, with the parameter of 'GameConstants!
 
	Runtime:CallMethodOn(Runtime:RequireChildren(script.Parent.Controllers), "OnInit", gameConstants)

CallSpawnedMethodOn

Runtime:CallSpawnedMethodOn( modules { { [any]: any } }, methodName string (opens in a new tab), arguments ... ) -> nil (opens in a new tab)

A simple function that will spawn a new function to call a method on an array of tables. Useful when used in combination with RequireDescendants/RequireChildren calls.

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
	
	local gameConstants = {
		...
	}
 
	-- require all modules under the 'Controllers' instance, call 'OnInit'
	-- function in each module, if it exists, with the parameter of 'GameConstants!
 
	Runtime:CallSpawnedMethodOn(Runtime:RequireChildren(script.Parent.Controllers), "OnInit", gameConstants)

SetFFValue

Runtime:SetFFValue( ffName string (opens in a new tab), value any ) -> nil (opens in a new tab)

A simple method to allow the developer to set runtime variables, useful when setting/getting metadata for the Runtime of a game.

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
 
	Runtime:RequireChildren(script.Parent.Controllers)
	Runtime:RequireChildren(script.Parent.Cameras)
	Runtime:RequireChildren(script.Parent.Components)
 
	Runtime:SetFFValue("IsLoaded", true)
	Runtime:SetFFValue("GameVersion", "0.1.0")

GetFFValue

Runtime:GetFFValue( ffName string (opens in a new tab) ) -> nil (opens in a new tab)

Fetch the value of a fast flag set by a different script.

	local Runtime = require(ReplicatedStorage.Packages.Runtime)
 
	local Module = {}
 
	function Module.OnInit()
		-- GameVersion is set by the loader script.
 
		Module.GameVersion = Runtime:GetFFValue("GameVersion")
	end
 
	return Module

Functions