feat(docs): updated example.md

This commit is contained in:
Khietsly Tristan 2026-02-13 14:58:54 +07:00
parent 920bd21094
commit e810c6e000
8 changed files with 142 additions and 137 deletions

View file

@ -7,13 +7,13 @@ For Client-sided
Create new Warp event. Create new Warp event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
Identifier: string Identifier: string
) )
``` ```
```lua [Example] ```luau [Example]
local Remote = Warp.Client("Remote") local Remote = Warp.Client("Remote")
``` ```
::: :::
@ -23,13 +23,13 @@ local Remote = Warp.Client("Remote")
Create new Warp events with array. Create new Warp events with array.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
{ any } { any }
) )
``` ```
```lua [Example] ```luau [Example]
local Events = Warp.fromClientArray({ local Events = Warp.fromClientArray({
"Remote1", "Remote1",
"Remote2", "Remote2",
@ -48,13 +48,13 @@ Events.Remote3:Connect(function(...) end)
Connect event to receive incoming from server way. Connect event to receive incoming from server way.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
callback: (...any) -> () callback: (...any) -> ()
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Connect(function(...) Remote:Connect(function(...)
print(...) print(...)
end) end)
@ -66,13 +66,13 @@ end)
This function likely `:Connect` but it disconnect the event once it fired. This function likely `:Connect` but it disconnect the event once it fired.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
callback: (...any) -> () callback: (...any) -> ()
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Once(function(...) Remote:Once(function(...)
print(...) print(...)
end) end)
@ -84,13 +84,13 @@ end)
Disconnect the event connection. Disconnect the event connection.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
key: string key: string
): boolean ): boolean
``` ```
```lua [Example] ```luau [Example]
local connection = Remote:Connect(function(player, ...) end) -- store the key local connection = Remote:Connect(function(player, ...) end) -- store the key
Remote:Disconnect(connection) Remote:Disconnect(connection)
@ -101,7 +101,7 @@ Remote:Disconnect(connection)
Disconnect All the event connection. Disconnect All the event connection.
```lua [Example] ```luau [Example]
Remote:DisconnectAll() Remote:DisconnectAll()
``` ```
@ -110,14 +110,14 @@ Remote:DisconnectAll()
Fire the event to the spesific server with data. Fire the event to the spesific server with data.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
reliable: boolean, reliable: boolean,
...: any ...: any
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Fire(true, "Hello World!") Remote:Fire(true, "Hello World!")
``` ```
::: :::
@ -131,14 +131,14 @@ This function have rate limiting it self and configured from server.
Semiliar to `:InvokeServer`, but it have timeout system that not exists on `RemoteFunction.InvokeServer`. Semiliar to `:InvokeServer`, but it have timeout system that not exists on `RemoteFunction.InvokeServer`.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
timeout: number, timeout: number,
...: any ...: any
) -> (...any) ) -> (...any)
``` ```
```lua [Example] ```luau [Example]
local Request = Remote:Invoke(2, "Hello World!") -- this yield until it response local Request = Remote:Invoke(2, "Hello World!") -- this yield until it response
``` ```
::: :::

View file

@ -9,7 +9,7 @@ Ratelimit is one of most useful feature.
When creating a event on Server, you can add second argument (optional) as table `rateLimit` to limit the number of times the event can be called and the interval for reset the counter on client-side. When creating a event on Server, you can add second argument (optional) as table `rateLimit` to limit the number of times the event can be called and the interval for reset the counter on client-side.
::: code-group ::: code-group
```lua [Server] ```luau [Server]
-- Server -- Server
-- Let's make the event have ratelimit with max 50 entrance for 2 seconds. -- Let's make the event have ratelimit with max 50 entrance for 2 seconds.
local Remote = Warp.Server("Remote1", { local Remote = Warp.Server("Remote1", {
@ -22,7 +22,7 @@ local Remote = Warp.Server("Remote1", {
-- No need anything to adds on client side. -- No need anything to adds on client side.
``` ```
```lua [Client] ```luau [Client]
-- Client -- Client
local Remote = Warp.Client("Remote1") -- Yields, retreive rateLimit configuration. local Remote = Warp.Client("Remote1") -- Yields, retreive rateLimit configuration.
-- The Event will automatic it self for retreiving the rate limit configuration from the server. -- The Event will automatic it self for retreiving the rate limit configuration from the server.

View file

@ -7,7 +7,7 @@ For Server-sided
Create new Warp event. Create new Warp event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
Identifier: string, Identifier: string,
rateLimit: { rateLimit: {
@ -17,7 +17,7 @@ Create new Warp event.
) )
``` ```
```lua [Example] ```luau [Example]
local Remote = Warp.Server("Remote") local Remote = Warp.Server("Remote")
``` ```
::: :::
@ -27,13 +27,13 @@ local Remote = Warp.Server("Remote")
Create new Warp events with array. Create new Warp events with array.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
{ any } { any }
) )
``` ```
```lua [Example] ```luau [Example]
local Events = Warp.fromServerArray({ local Events = Warp.fromServerArray({
["Remote1"] = { ["Remote1"] = {
rateLimit = { rateLimit = {
@ -60,14 +60,14 @@ Events.Remote3:Connect(function(player, ...) end)
Connect event to receive incoming from client way. Connect event to receive incoming from client way.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
player: Player, player: Player,
callback: (...any) -> () callback: (...any) -> ()
): string ): string
``` ```
```lua [Example] ```luau [Example]
Remote:Connect(function(player, ...) Remote:Connect(function(player, ...)
print(player, ...) print(player, ...)
end) end)
@ -79,14 +79,14 @@ end)
This function likely `:Connect` but it disconnect the event once it fired. This function likely `:Connect` but it disconnect the event once it fired.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
player: Player, player: Player,
callback: (...any) -> () callback: (...any) -> ()
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Once(function(player, ...) Remote:Once(function(player, ...)
print(player, ...) print(player, ...)
end) end)
@ -98,13 +98,13 @@ end)
Disconnect the event connection. Disconnect the event connection.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
key: string key: string
): boolean ): boolean
``` ```
```lua [Example] ```luau [Example]
local connection = Remote:Connect(function(player, ...) end) -- store the key local connection = Remote:Connect(function(player, ...) end) -- store the key
Remote:Disconnect(connection) Remote:Disconnect(connection)
@ -115,7 +115,7 @@ Remote:Disconnect(connection)
Disconnect All the event connection. Disconnect All the event connection.
```lua [Example] ```luau [Example]
Remote:DisconnectAll() Remote:DisconnectAll()
``` ```
@ -124,7 +124,7 @@ Remote:DisconnectAll()
Fire the event to a client. Fire the event to a client.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
reliable: boolean, reliable: boolean,
player: Player, player: Player,
@ -132,7 +132,7 @@ Fire the event to a client.
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Fire(true, player, "Hello World!") Remote:Fire(true, player, "Hello World!")
``` ```
::: :::
@ -142,14 +142,14 @@ Remote:Fire(true, player, "Hello World!")
Fire the event to all clients. Fire the event to all clients.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
reliable: boolean, reliable: boolean,
...: any ...: any
) )
``` ```
```lua [Example] ```luau [Example]
Remote:Fires(true, "Hello World!") Remote:Fires(true, "Hello World!")
``` ```
::: :::
@ -159,7 +159,7 @@ Remote:Fires(true, "Hello World!")
Fire the event to all clients but except a players. Fire the event to all clients but except a players.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
reliable: boolean, reliable: boolean,
except: { Player }, except: { Player },
@ -167,7 +167,7 @@ Fire the event to all clients but except a players.
) )
``` ```
```lua [Example] ```luau [Example]
Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World!") -- this will sent to all players except { Players.Eternity_Devs, Players.Player2 }. Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World!") -- this will sent to all players except { Players.Eternity_Devs, Players.Player2 }.
``` ```
::: :::
@ -177,7 +177,7 @@ Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World
Semiliar to `:InvokeClient`, but it have timeout system that not exists on `RemoteFunction.InvokeClient`. Semiliar to `:InvokeClient`, but it have timeout system that not exists on `RemoteFunction.InvokeClient`.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
timeout: number, timeout: number,
player: Player, player: Player,
@ -185,7 +185,7 @@ Semiliar to `:InvokeClient`, but it have timeout system that not exists on `Rem
) -> (...any) ) -> (...any)
``` ```
```lua [Example] ```luau [Example]
local Request = Remote:Invoke(2, player, "Hello World!") local Request = Remote:Invoke(2, player, "Hello World!")
``` ```
::: :::

View file

@ -7,13 +7,13 @@ A alternative of BindableEvent.
Create new Signal. Create new Signal.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
Identifier: string Identifier: string
) )
``` ```
```lua [Example] ```luau [Example]
local Signal1 = Warp.Signal("Signal1") local Signal1 = Warp.Signal("Signal1")
``` ```
::: :::
@ -23,13 +23,13 @@ local Signal1 = Warp.Signal("Signal1")
Create new Signal. Create new Signal.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
{ string } { string }
) )
``` ```
```lua [Example] ```luau [Example]
local Signals = Warp.fromSignalArray({"Signal1", "Signal2"}) local Signals = Warp.fromSignalArray({"Signal1", "Signal2"})
Signals.Signal1:Connect(function(...) end) Signals.Signal1:Connect(function(...) end)
Signals.Signal2:Connect(function(...) end) Signals.Signal2:Connect(function(...) end)
@ -39,13 +39,13 @@ Signals.Signal2:Connect(function(...) end)
## `:Connect` ## `:Connect`
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
callback: (...any) -> () callback: (...any) -> ()
) )
``` ```
```lua [Example] ```luau [Example]
Signal1:Connect(function(...) Signal1:Connect(function(...)
print(...) print(...)
end) end)
@ -57,13 +57,13 @@ end)
This function likely `:Connect` but it disconnect the signal once it fired. This function likely `:Connect` but it disconnect the signal once it fired.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
callback: (...any) -> () callback: (...any) -> ()
) )
``` ```
```lua [Example] ```luau [Example]
Signal1:Once(function(...) Signal1:Once(function(...)
print(...) print(...)
end) end)
@ -75,13 +75,13 @@ end)
Disconnect the signal connection. Disconnect the signal connection.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
key: string key: string
) )
``` ```
```lua [Example] ```luau [Example]
local connection = Signal1:Connect(function(...) end) -- store the key local connection = Signal1:Connect(function(...) end) -- store the key
Signal1:Disconnect(connection) Signal1:Disconnect(connection)
@ -96,7 +96,7 @@ This requires `key` to disconnect a signal connection.
Disconnect All signal connections. Disconnect All signal connections.
```lua [Example] ```luau [Example]
Signal1:DisconnectAll() Signal1:DisconnectAll()
``` ```
@ -105,13 +105,13 @@ Signal1:DisconnectAll()
Fire the signal (Immediate) Fire the signal (Immediate)
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
...: any ...: any
) )
``` ```
```lua [Example] ```luau [Example]
Signal1:Fire("Hello World!") Signal1:Fire("Hello World!")
``` ```
::: :::
@ -121,13 +121,13 @@ Signal1:Fire("Hello World!")
Fire the signal (Deferred) Fire the signal (Deferred)
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
...: any ...: any
) )
``` ```
```lua [Example] ```luau [Example]
Signal1:Fire("Hello World!") Signal1:Fire("Hello World!")
``` ```
::: :::
@ -141,14 +141,14 @@ This uses `pcall`, which means it never error (safe-mode, sacrificed debugging),
Fire to other signal, this uses `:Fire`. Fire to other signal, this uses `:Fire`.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
signal: string, signal: string,
...: any ...: any
) )
``` ```
```lua [Example] ```luau [Example]
Signals.Signal1:FireTo("Signal2", "Hello World!") Signals.Signal1:FireTo("Signal2", "Hello World!")
``` ```
::: :::
@ -160,14 +160,14 @@ This requires `key`.
## `:Invoke` <Badge type="warning" text="yield" /> ## `:Invoke` <Badge type="warning" text="yield" />
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
key: string, key: string,
...: any ...: any
) -> (...any) ) -> (...any)
``` ```
```lua [Example] ```luau [Example]
local connection = Signal1:Conenct(function(...) return "hey!" end) local connection = Signal1:Conenct(function(...) return "hey!" end)
local Request = Signal1:Invoke(connection, "Hello World!") local Request = Signal1:Invoke(connection, "Hello World!")
``` ```
@ -178,7 +178,7 @@ local Request = Signal1:Invoke(connection, "Hello World!")
this use `:Invoke`. this use `:Invoke`.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
signal: string, signal: string,
key: string, key: string,
@ -186,7 +186,7 @@ this use `:Invoke`.
) -> (...any) ) -> (...any)
``` ```
```lua [Example] ```luau [Example]
local connection2 = Signals.Signal2:Conenct(function(...) return "hey!" end) local connection2 = Signals.Signal2:Conenct(function(...) return "hey!" end)
local Request = Signals.Signal1:Invoke("Signal2", connection2, "Hello World!") local Request = Signals.Signal1:Invoke("Signal2", connection2, "Hello World!")
``` ```

View file

@ -58,13 +58,13 @@ Define strict data schemas for optimized serialization and type safety.
Create a new buffer writer for serializing data. Create a new buffer writer for serializing data.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
capacity: number? -- Optional initial capacity (default: 64) capacity: number? -- Optional initial capacity (default: 64)
): Writer ): Writer
``` ```
```lua [Example] ```luau [Example]
local Buffer = Warp.Buffer() local Buffer = Warp.Buffer()
local writer = Buffer.createWriter(256) -- Pre-allocate 256 bytes local writer = Buffer.createWriter(256) -- Pre-allocate 256 bytes
``` ```
@ -75,13 +75,13 @@ local writer = Buffer.createWriter(256) -- Pre-allocate 256 bytes
Build the final buffer for transmission. Build the final buffer for transmission.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
writer: Writer writer: Writer
): buffer -- Returns buffer ): buffer -- Returns buffer
``` ```
```lua [Example] ```luau [Example]
local Buffer = Warp.Buffer() local Buffer = Warp.Buffer()
local writer = Buffer.createWriter() local writer = Buffer.createWriter()
@ -100,13 +100,13 @@ print(buffer.len(finalBuffer))
Build the final buffer with instance references for transmission. Build the final buffer with instance references for transmission.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
writer: Writer writer: Writer
): (buffer, { Instance }?) -- Returns buffer and optional instance references ): (buffer, { Instance }?) -- Returns buffer and optional instance references
``` ```
```lua [Example] ```luau [Example]
local Buffer = Warp.Buffer() local Buffer = Warp.Buffer()
local writer = Buffer.createWriter() local writer = Buffer.createWriter()
@ -125,13 +125,13 @@ print(buffer.len(finalBuffer), refs)
Reset a writer for reuse, clearing all data. Reset a writer for reuse, clearing all data.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
writer: Writer writer: Writer
) )
``` ```
```lua [Example] ```luau [Example]
local Buffer = Warp.Buffer() local Buffer = Warp.Buffer()
local writer = Buffer.createWriter() local writer = Buffer.createWriter()

View file

@ -13,14 +13,14 @@ local Client = Warp.Client()
Connect to an event to receive incoming data from the server. Connect to an event to receive incoming data from the server.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
fn: (...any) -> ...any fn: (...any) -> ...any
) -> Connection ) -> Connection
``` ```
```lua [Example] ```luau [Example]
local connection = Client.Connect("ServerNotify", function(message, sender) local connection = Client.Connect("ServerNotify", function(message, sender)
print(`Server message from {sender}: {message}`) print(`Server message from {sender}: {message}`)
end) end)
@ -33,14 +33,14 @@ print(connection.Connected)
Similar to `:Connect` but automatically disconnects after the first firing. Similar to `:Connect` but automatically disconnects after the first firing.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
fn: (...any) -> ...any fn: (...any) -> ...any
) -> Connection ) -> Connection
``` ```
```lua [Example] ```luau [Example]
Client.Once("WelcomeMessage", function(welcomeText) Client.Once("WelcomeMessage", function(welcomeText)
print(`Welcome: {welcomeText}`) print(`Welcome: {welcomeText}`)
end) end)
@ -52,13 +52,13 @@ end)
Wait for an event to be triggered. Wait for an event to be triggered.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) -> (number, ...any) ) -> (number, ...any)
``` ```
```lua [Example] ```luau [Example]
local elapsed, message = Client.Wait("ServerMessage") local elapsed, message = Client.Wait("ServerMessage")
print(`Received message after {elapsed} seconds: {message}`) print(`Received message after {elapsed} seconds: {message}`)
``` ```
@ -69,11 +69,11 @@ print(`Received message after {elapsed} seconds: {message}`)
Disconnect the event connection. Disconnect the event connection.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
() ()
``` ```
```lua [Example] ```luau [Example]
local connection = Client.Connect("ServerNotify", function(message, sender) local connection = Client.Connect("ServerNotify", function(message, sender)
print(`Server message from {sender}: {message}`) print(`Server message from {sender}: {message}`)
-- Disconnect the connection -- Disconnect the connection
@ -88,13 +88,13 @@ print(Connection.Connected)
Disconnect all connections for a specific event. Disconnect all connections for a specific event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) )
``` ```
```lua [Example] ```luau [Example]
Client.DisconnectAll("ServerNotify") Client.DisconnectAll("ServerNotify")
``` ```
::: :::
@ -104,13 +104,13 @@ Client.DisconnectAll("ServerNotify")
Disconnect all connections and remove the event. Disconnect all connections and remove the event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) )
``` ```
```lua [Example] ```luau [Example]
Client.Destroy("ServerNotify") Client.Destroy("ServerNotify")
``` ```
::: :::
@ -120,7 +120,7 @@ Client.Destroy("ServerNotify")
Fire an event to the server. Fire an event to the server.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
reliable: boolean, reliable: boolean,
@ -128,7 +128,7 @@ Fire an event to the server.
) )
``` ```
```lua [Example] ```luau [Example]
-- (TCP) Reliable event (guaranteed delivery) -- (TCP) Reliable event (guaranteed delivery)
Client.Fire("PlayerAction", true, "jump", playerPosition) Client.Fire("PlayerAction", true, "jump", playerPosition)
@ -142,7 +142,7 @@ Client.Fire("PositionUpdate", false, currentPosition)
Invoke the server with timeout support. Invoke the server with timeout support.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
timeout: number?, timeout: number?,
@ -150,7 +150,7 @@ Invoke the server with timeout support.
) -> ...any ) -> ...any
``` ```
```lua [Example] ```luau [Example]
local Client = Warp.Client() local Client = Warp.Client()
local response = Client.Invoke("RequestData", 3, "playerStats") local response = Client.Invoke("RequestData", 3, "playerStats")
if response then if response then
@ -170,14 +170,14 @@ This function is yielded. Returns `nil` if timeout occurs.
Define a schema for strict data packing on a specific event. Define a schema for strict data packing on a specific event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
schema: Buffer.SchemaType schema: Buffer.SchemaType
) )
``` ```
```lua [Example] ```luau [Example]
local Client = Warp.Client() local Client = Warp.Client()
-- Define a schema for position updates -- Define a schema for position updates

View file

@ -13,14 +13,14 @@ local Server = Warp.Server()
Connect to an event to receive incoming data from clients. Connect to an event to receive incoming data from clients.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
fn: (player: Player, ...any) -> ...any fn: (player: Player, ...any) -> ...any
) -> Connection ) -> Connection
``` ```
```lua [Example] ```luau [Example]
local connection = Server.Connect("ServerNotify", function(player, message) local connection = Server.Connect("ServerNotify", function(player, message)
print(`Client message from {player}: {message}`) print(`Client message from {player}: {message}`)
end) end)
@ -33,14 +33,14 @@ print(connection.Connected)
Similar to `:Connect` but automatically disconnects after the first firing. Similar to `:Connect` but automatically disconnects after the first firing.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
fn: (player: Player, ...any) -> ...any fn: (player: Player, ...any) -> ...any
) -> Connection ) -> Connection
``` ```
```lua [Example] ```luau [Example]
Server.Once("WelcomeMessage", function(welcomeText) Server.Once("WelcomeMessage", function(welcomeText)
print(`Welcome: {welcomeText}`) print(`Welcome: {welcomeText}`)
end) end)
@ -52,13 +52,13 @@ end)
Wait for an event to be triggered. Wait for an event to be triggered.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) -> (number, ...any) ) -> (number, ...any)
``` ```
```lua [Example] ```luau [Example]
local elapsed, message = Server.Wait("ServerMessage") local elapsed, message = Server.Wait("ServerMessage")
print(`Received message after {elapsed} seconds: {message}`) print(`Received message after {elapsed} seconds: {message}`)
``` ```
@ -69,13 +69,13 @@ print(`Received message after {elapsed} seconds: {message}`)
Disconnect all connections for a specific event. Disconnect all connections for a specific event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) )
``` ```
```lua [Example] ```luau [Example]
Server.DisconnectAll("ServerNotify") Server.DisconnectAll("ServerNotify")
``` ```
::: :::
@ -85,13 +85,13 @@ Server.DisconnectAll("ServerNotify")
Disconnect all connections and remove the event. Disconnect all connections and remove the event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string remoteName: string
) )
``` ```
```lua [Example] ```luau [Example]
Server.Destroy("ServerNotify") Server.Destroy("ServerNotify")
``` ```
::: :::
@ -101,7 +101,7 @@ Server.Destroy("ServerNotify")
Fire an event to a specific player. Fire an event to a specific player.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
reliable: boolean, reliable: boolean,
@ -110,7 +110,7 @@ Fire an event to a specific player.
) )
``` ```
```lua [Example] ```luau [Example]
Server.Fire("ServerNotify", true, player, "Hello from server!") Server.Fire("ServerNotify", true, player, "Hello from server!")
``` ```
::: :::
@ -120,7 +120,7 @@ Server.Fire("ServerNotify", true, player, "Hello from server!")
Fire an event to all connected players. Fire an event to all connected players.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
reliable: boolean, reliable: boolean,
@ -128,7 +128,7 @@ Fire an event to all connected players.
) )
``` ```
```lua [Example] ```luau [Example]
Server.Fires("Broadcast", true, "Server announcement!") Server.Fires("Broadcast", true, "Server announcement!")
``` ```
::: :::
@ -138,7 +138,7 @@ Server.Fires("Broadcast", true, "Server announcement!")
Fire an event to all players except specified ones. Fire an event to all players except specified ones.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
reliable: boolean, reliable: boolean,
@ -147,7 +147,7 @@ Fire an event to all players except specified ones.
) )
``` ```
```lua [Example] ```luau [Example]
local excludedPlayers = { player1, player2 } local excludedPlayers = { player1, player2 }
Server.FireExcept("Update", true, excludedPlayers, "Game update") Server.FireExcept("Update", true, excludedPlayers, "Game update")
``` ```
@ -158,7 +158,7 @@ Server.FireExcept("Update", true, excludedPlayers, "Game update")
Invoke a client with timeout support. Invoke a client with timeout support.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
player: Player, player: Player,
@ -167,7 +167,7 @@ Invoke a client with timeout support.
) -> ...any ) -> ...any
``` ```
```lua [Example] ```luau [Example]
local response = Server.Invoke("RequestData", player, 3, "userInfo") local response = Server.Invoke("RequestData", player, 3, "userInfo")
if response then if response then
print("Client responded:", response) print("Client responded:", response)
@ -186,14 +186,14 @@ This function is yielded. Returns `nil` if timeout occurs.
Define a schema for strict data packing on a specific event. Define a schema for strict data packing on a specific event.
::: code-group ::: code-group
```lua [Variable] ```luau [Variable]
( (
remoteName: string, remoteName: string,
schema: Buffer.SchemaType schema: Buffer.SchemaType
) )
``` ```
```lua [Example] ```luau [Example]
local Server = Warp.Server() local Server = Warp.Server()
local dataSchema = Server.Schema.struct({ local dataSchema = Server.Schema.struct({

View file

@ -1,71 +1,76 @@
# Example <Badge type="tip" text="1.0" /> # Example <Badge type="tip" text="1.1" />
Let's try and play something with Warp! Let's try and play something with Warp!
::: code-group ::: code-group
```lua [Server] ```luau [Schemas]
local Warp = require("path.to.module") local Schema = require(path.to.warp).Buffer.Schema
-- Events return {
local Example = Warp.Server("Example") Example = Schema.array(Schema.string()),
local Ping = Warp.Server("Ping") Ping = Schema.string(),
local Pong = Warp.Server("Pong") Pong = Schema.string(),
local PingAll = Warp.Server("PingAll") PingAll = Schema.string(),
}
```
```luau [Server]
local Warp = require(path.to.warp).Server()
local Schemas = require(path.to.schemas)
Example:Connect(function(player, arg1, arg2) -- Use schemas
print(arg1, arg2) for eventName, schema in Schemas do
return "Whooo!" Warp.useSchema(eventName, schema)
end
Warp.Connect("Example", function(player, arg)
print(table.unpack(arg))
return "Hey!"
end) end)
Warp.Connect("Ping", function(player, ping)
Ping:Connect(function(player, ping)
if ping then if ping then
print("PING!") print("PING!")
Pong:Fire(true, player, "pong!") Warp.Fire("Pong", true, player, "pong!") -- Fire to spesific player through reliable event
PingAll:Fires(true, "ey!") Warp.Fire("PingAll", true, "ey!") -- Fire to all clients through reliable event
end end
end) end)
``` ```
```lua [Client] ```luau [Client]
local Players = game:GetService("Players") local Players = game:GetService("Players")
local Warp = require("path.to.module") local Warp = require(path.to.warp).Client()
local Schemas = require(path.to.schemas)
-- Events -- Use schemas
local Example = Warp.Client("Example") for eventName, schema in Schemas do
local Ping = Warp.Client("Ping") Warp.useSchema(eventName, schema)
local Pong = Warp.Client("Pong") end
local PingAll = Warp.Client("PingAll")
-- Connect the events -- Connect the events
local connection1 local connection1
connection1 = Pong:Connect(function(pong: boolean) connection1 = Warp.Connect("Pong", function(pong: boolean) -- we store the connection so we can disconnect it later
if pong then if pong then
print("PONG!") print("PONG!")
end end
end) end)
Warp.Connect("PingAll", function(isPing: boolean)
PingAll:Connect(function(isPing: boolean)
if isPing then if isPing then
print("I GET PINGED!") print("I GET PINGED!")
end end
end) end)
-- Try request a event from server! -- Try request a event from server!
print(Example:Invoke(5, "Hello!", "this is from > "..Players.LocalPlayer.Name)) print(Warp.Invoke("Example", 1, { "Hello!", `this is from: @{Players.LocalPlayer.Name}` }))
-- Do a ping & pong to server! -- Do a ping & pong to server!
Ping:Fire(true, "ping!") Warp.Fire("Ping", true, "ping!") -- we send through reliable event
task.wait(1) -- lets wait 1 seconds! task.wait(1) -- lets wait 1 seconds!
-- Disconnect All the events -- Disconnect All the events
Pong:DisconnectAll() connection1:DisconnectAll()
PingAll:DisconnectAll() -- or just disconnect spesific connection
-- or Just disconnect spesific connection Warp.Disconnect("PingAll")
Pong:Disconnect(connection1)
-- Destroying/Deleting a Event? -- Destroying/Deleting a Event?
Pong:Destroy() Warp.Destroy("Pong")
-- Yay Done!
``` ```
::: :::