• Stars
    star
    535
  • Rank 82,940 (Top 2 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight game framework for Roblox

Release Lint Deploy Docs

Knit

Knit is a lightweight framework for Roblox that simplifies communication between core parts of your game and seamlessly bridges the gap between the server and the client.

Read the documentation for more info.

Install

Installing Knit is very simple. Just drop the module into ReplicatedStorage. Knit can also be used within a Rojo project.

Roblox Studio workflow:

  1. Get Knit from the Roblox library.
  2. Place Knit directly within ReplicatedStorage.

Wally & Rojo workflow:

  1. Add Knit as a Wally dependency (e.g. Knit = "sleitnick/knit@^1")
  2. Use Rojo to point the Wally packages to ReplicatedStorage.

Basic Usage

The core usage of Knit is the same from the server and the client. The general pattern is to create a single script on the server and a single script on the client. These scripts will load Knit, create services/controllers, and then start Knit.

The most basic usage would look as such:

local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)

Knit.Start():catch(warn)
-- Knit.Start() returns a Promise, so we are catching any errors and feeding it to the built-in 'warn' function
-- You could also chain 'await()' to the end to yield until the whole sequence is completed:
--    Knit.Start():catch(warn):await()

That would be the necessary code on both the server and the client. However, nothing interesting is going to happen. Let's dive into some more examples.

A Simple Service

A service is simply a structure that serves some specific purpose. For instance, a game might have a MoneyService, which manages in-game currency for players. Let's look at a simple example:

local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)

-- Create the service:
local MoneyService = Knit.CreateService {
	Name = "MoneyService",
}

-- Add some methods to the service:

function MoneyService:GetMoney(player)
	-- Do some sort of data fetch
	local money = someDataStore:GetAsync("money")
	return money
end

function MoneyService:GiveMoney(player, amount)
	-- Do some sort of data fetch
	local money = self:GetMoney(player)
	money += amount
	someDataStore:SetAsync("money", money)
end

Knit.Start():catch(warn)

Now we have a little MoneyService that can get and give money to a player. However, only the server can use this at the moment. What if we want clients to fetch how much money they have? To do this, we have to create some client-side code to consume our service. We could create a controller, but it's not necessary for this example.

First, we need to expose a method to the client. We can do this by writing methods on the service's Client table:

-- Money service on the server
...
function MoneyService.Client:GetMoney(player)
	-- We already wrote this method, so we can just call the other one.
	-- 'self.Server' will reference back to the root MoneyService.
	return self.Server:GetMoney(player)
end
...

We can write client-side code to fetch money from the service:

-- Client-side code
local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
Knit.Start():catch(warn):await()

local MoneyService = Knit.GetService("MoneyService")

MoneyService:GetMoney():andThen(function(money)
	print(money)
end)

Under the hood, Knit is creating a RemoteFunction bound to the service's GetMoney method. Knit keeps RemoteFunctions and RemoteEvents out of the way so that developers can focus on writing code and not building networking infrastructure.

More Repositories

1

AeroGameFramework

AeroGameFramework is a Roblox game framework that makes development easy and fun. The framework is designed to simplify the communication between modules and seamlessly bridge the gap between the server and client.
Lua
215
star
2

RbxUtil

A collection of utility modules for Roblox.
Lua
205
star
3

rbxcloud

CLI and library for Roblox Open Cloud API
Rust
86
star
4

RbxCameraShaker

Camera shake effects for Roblox games
Lua
64
star
5

RbxCookbook

Useful snippets of Lua code for the Roblox platform.
Lua
57
star
6

rbxts-proton

Experimental framework for Roblox game development
TypeScript
25
star
7

RbxAWS

[Under Development] AWS SDK for Roblox
Lua
17
star
8

RbxObservers

Utility observer functions
Lua
17
star
9

rbxts-octo-tree

Octree implementation
Lua
14
star
10

LuaOption

Option class for Lua
Lua
12
star
11

Axis

A provider framework for the Roblox ecosystem
Lua
11
star
12

RDC2019-Procedural-Generation

Resources from the Procedural Generation talk from RDC2019
11
star
13

Luambda

Lua runtime for AWS Lambda
Lua
6
star
14

lines-of-code

Roblox plugin for displaying the lines of code in a Roblox experience.
TypeScript
6
star
15

PIDebug

A simple visual web debugger for PIDs, allowing both live data of the PID system and ability to configure the PID variables.
TypeScript
5
star
16

rbx-doc-search

Roblox Creator Docs search extension and data aggregation
JavaScript
5
star
17

LunarServer

A stateless, multi-threaded, and easy Lua server runtime.
C
4
star
18

RbxDevSearch

Search the Roblox developer hub
JavaScript
4
star
19

MoneyPlant

Test game for Knit
Lua
4
star
20

rbxts-silo

State management
TypeScript
4
star
21

RbxPolyReg

Polynomial Regression for Lua/Roblox
Lua
4
star
22

rbx-ci-test

Lua
3
star
23

RbxData

Web-based browser for Roblox DataStores
3
star
24

rbxts-wait-for

TypeScript
3
star
25

AeroGameFramework-VSCE

Visual Studio Code extension for AeroGameFramework
TypeScript
2
star
26

rbxts-trove

Class for tracking and cleaning up objects
TypeScript
2
star
27

the-cloud

Cloud API Demo
Python
1
star
28

InstallAPK

APK installer to make testing a bit faster
Java
1
star
29

knit-cli

CLI tool for Knit
1
star
30

now

A simple and lightweight "New Tab" page for Chrome
JavaScript
1
star
31

ToGIF

Convert video files to GIF files
Python
1
star
32

rbxts-streamable

TypeScript
1
star
33

rbxts-beacon

Beacon is a signal implementation for sending and receiving events
TypeScript
1
star
34

Sleitnick.github.io

JavaScript
1
star