Providers
This article is a stub. You can help Prvd 'M Wrong by expanding it.
Prvd 'M Wrong is used to create service providers, which provide a specific function for a game. Use providers to compose the top-level logic of a game.
Setup
Prvd 'M Wrong is boring. You get the freedom to structure a game however you like and use whatever complementary libraries you want. This article assumes the following structure, though you are free to divvy it up:
Let's keep the startup code in
Server.server.luau
.ts
. Prvd 'M Wrong games begin with
a starting root.
Create a starting root with prvd.root()
:
Most Prvd 'M Wrong games store providers inside ModuleScripts. Let's include all
descendant modules in the Providers
directory through useModules()
:
Now Prvd 'M Wrong can be started:
That's the bare minimum needed to start a Prvd 'M Wrong game. start()
returns
a started root which can be stopped by calling stop()
:
Roots will be further elaborated later. Now, you can make Prvd 'M Wrong's simplest object: providers.
Providers
Prvd 'M Wrong is used to create service providers, which provide a specific function for a game. Use providers to compose the top-level logic of a game.
As your first provider, lets create a provider to track some player session information.
Create a new ModuleScript under the Providers directory called PlayerProvider
.
Then, create a new table for your provider:
PlayerProvider.luau | |
---|---|
To construct a provider, call prvd
as if it is a constructor with the
provider:
It's strongly recommended to module return the provider constructed from
prvd()
so providers can be gradually built up before being returned by the
module. This allows Luau to infer useful types and for Prvd 'M Wrong to
automatically name it after the ModuleScript name.
Do NOT lazily instantiate a provider with prvd()
, this "seals" the provider
and will cause type errors:
-- bad!
local PlayerProvider = prvd({})
-- TypeError: Cannot add property 'someFutureProperty' to table '{ }' & '{| loadOrder: ... |}'
PlayerProvider.someFutureProperty = {}
return PlayerProvider
Do NOT instantiate the prvd()
in one go, this worsens Luau type safety:
-- bad!
return prvd {
someFutureMethod = function(self)
-- self is inferred as `a` here... not very useful!
end
}
DO gradually build the provider, then wrap the module return with prvd()
:
Create a new ModuleScript under the Providers directory called PlayerProvider
.
Then, create a new class for your provider:
To construct a provider, import the Provider
class decorator from Prvd 'M
Wrong and use it:
Games often track player session information, such as when the player joined or
the player's leaderstats. Let's define a PlayerSession
type, along with an
playerSessions
property to store each player's session information:
Lifecycles
Dependencies
Why Providers?
Luau
TypeScript