Basic Usage
For first, visit the Installation page to install the Wisp library in your game/project
Before Start
For first, require the imported library:
local Wisp = require(game.ReplicatedStorage.Wisp) -- or everywhereDue to problems with LSP Roblox (Luau), you will have to get the execution side (Client, Server) yourself. Here's how it works:
local Wisp = require(game.ReplicatedStorage.Wisp).Client
-- Now you can freely use Wisplocal Wisp = require(game.ReplicatedStorage.Wisp).Server
-- Now you can freely use WispAwaitReady
If there are a lot of RemoteEvents/RemoteFunctions or if the hardware is poor, the client may not be able to initialize correctly. Therefore, it is recommended to use the Wisp.AwaitReady() method before using it in LocalScript, as follows:
local Wisp = require(game.ReplicatedStorage.Wisp).Client
Wisp.AwaitReady()-- You can also pass the AwaitReady timeout
-- and check whether the Wisp is initialized or not
local Wisp = require(game.ReplicatedStorage.Wisp).Client
local IsWispReady: boolean = Wisp.AwaitReady(10) -- after the time has elapsed, it will display warn in the Output
if not IsWispReady then
error("Can't start, Wisp is not ready") -- optional
endFire & Connect
Wisp.Fire and Wisp.Connect are similar to the usual behavior of RemoteEvents. Let's take a closer look at Wisp.Fire and Wisp.Connect:
local Wisp = require(game.ReplicatedStorage.Wisp).Client
Wisp.AwaitReady()
Wisp.Fire("player_joined", "I'm new here:)") -- will send RemoteEvent with name "player_joined"
-- there can be as many arguments as you like, and almost any typelocal Wisp = require(game.ReplicatedStorage.Wisp).Server
Wisp.Connect("player_joined", function(player: Player, message: string) -- the player is always passed as the first argument
print(`{player.Name} Joined. Welcome! Player Message: {message}`)
end)
-- or:
Wisp.Once("player_joined", function(player: Player, message: string) -- listen once, auto-disconnects
print(`{player.Name} Joined. Welcome! Player Message: {message}`)
end)- PlayerName Joined. Welcome! Player Message: I'm new here:)The Server-Side also has additional sending functions:
local Wisp = require(game.ReplicatedStorage.Wisp).Server
-- Send to all players
Wisp.FireAll(remoteName: string, ...: any)
-- Send to a list of players
Wisp.FireList(remoteName: string, players: {Player}, ...: any)
-- Send to everyone except
Wisp.FireExcept(remoteName: string, except: Player | {Player}, ...: any)The client also has an additional method, namely Wisp.Wait():
local Wisp = require(game.ReplicatedStorage.Wisp).Client
Wisp.AwaitReady()
local message: string? = Wisp.Wait("private_message") -- Infinity waiting
print("Got message:", message)
local message: boolean? = Wisp.Wait("match_start", 30) -- 30s waiting
if message then
print("Match starting!")
else
print("Timeout - no match found")
endInvoke & OnInvoke
Wisp.Invoke and Wisp.OnInvoke are similar to the normal behavior of RemoteFunction.Invoke and RemoteFunction.OnInvoke, respectively:
local Wisp = require(game.ReplicatedStorage.Wisp).Client
Wisp.AwaitReady()
local ServerTime: number = Wisp.Invoke("get_time")
print("Server Time:", ServerTime)local Wisp = require(game.ReplicatedStorage.Wisp).Server
Wisp.OnInvoke("get_time", function(_player: Player)
return os.time()
end)- Server Time: 1777266546Wisp.Invoke and Wisp.OnInvoke also accept an infinite number of arguments of almost all types, as do Wisp.Fire and Wisp.Connect.
