1.3.1 • Published 3 years ago

@rbxts/simplesignals v1.3.1

Weekly downloads
87
License
MIT
Repository
github
Last release
3 years ago

SimpleSignals

A Roblox-TS RemoteEvent/RemoteFunction/BindableEvent wrapper which puts and end to the hassle of managing events. You can get straight to connecting and firing without any WaitForChild/Instance.new boilerplate, while your event instances get created automatically in the background.

Usage

Example: working with an event called "z"

SimpleClient.on("z", callbackFunc)

gets called on the client, but z doesn't exist. SimpleSignals will WaitForChild("z") on the event folder, and when the event gets created on the server, it connects callbackFunc to it. But how do events get created? Any time you call a z RemoteEvent related function on the server (on(z, once(z, fire(z), a RemoteEvent with name z gets created - if such a RemoteEvent doesn't exist. RemoteEvents/RemoteFunctions cannot be created on the client. The same process follows for RemoteFunctions and BindableEvents (note that BindableEvents aren't parented anywhere).

You can import the module this way on the server:

import { Server as SimpleSignals } from "@rbxts/simplesignals";

and on the client:

import { Client as SimpleSignals } from "@rbxts/simplesignals";

SimpleSignals manages events cleanly, without you having to instantiate or to WaitForChild:

SimpleClient.on("printX", (player, x) => {
	print(x);
});
SimpleClient.fire("printX", "X");

You never have to create objects you only use once:

const printX = new Instance("RemoteEvent");
printX.Name = "printX";
printX.Parent = game.GetService("ReplicatedStorage");

printX.OnServerEvent.Connect((player, x) => {
	print(x);
});
const printX = game.GetService("ReplicatedStorage").WaitForChild("printX");

printX.FireServer("X");

The following table describes where each event is stored:

Event typeGame locationFolder namePath
RemoteEventReplicatedStorageRemoteEventsgame.ReplicatedStorage.RemoteEvents
RemoteFunctionReplicatedStorageRemoteFunctionsgame.ReplicatedStorage.RemoteFunctions
BindableEventnone*

*BindableEvents aren't parented anywhere. They're stored in an internal table.

API

  • Simple:setCallback(name: string, callback: Function) → Promise<void>
  • Simple:invoke(name: string, ...args) → Promise<T>
  • Simple:registerFunction(name: string) → void (only on the server)
  • Simple:onBindable(name: string, callback: Function) → RBXScriptConnection
  • Simple:onceBindable(name: string, callback: Function) → void
  • Simple:fireBindable(name: string, ...args) → void

Examples

Redeem a code for a reward

main.server.ts
import { Server as simple } from "@rbxts/simplesignals";

const rewards = {
	"ABC123": 500,
	"1thousand": 1000
}
simple.on("redeemCode", (player, code: string) => {
	const reward = rewards[code];
	
	if (reward) {
		print(`${player.Name} just got ${reward} Coins!`);
	}
});
main.client.ts
import { Client as simple } from "@rbxts/simplesignals";
import { Players } from "@rbxts/services";
const LocalPlayer = Players.LocalPlayer;

const screenGui = new Instance("ScreenGui");
screenGui.Parent = LocalPlayer.WaitForChild("PlayerGui") as Folder;
const textBox = new Instance("TextBox");
textBox.Position = UDim2.fromScale(0.5, 0.5);
textBox.Parent = screenGui;

textBox.FocusLost.Connect(enterPressed => {
	if (enterPressed) simple.fire("redeemCode", textBox.Text);
});
1.3.1

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

2.0.0

3 years ago