2026-02-13 07:58:54 +00:00
|
|
|
# Example <Badge type="tip" text="1.1" />
|
2024-01-05 12:14:38 +00:00
|
|
|
|
|
|
|
|
Let's try and play something with Warp!
|
|
|
|
|
|
|
|
|
|
::: code-group
|
2026-02-13 07:58:54 +00:00
|
|
|
```luau [Schemas]
|
|
|
|
|
local Schema = require(path.to.warp).Buffer.Schema
|
2024-01-05 12:14:38 +00:00
|
|
|
|
2026-02-13 07:58:54 +00:00
|
|
|
return {
|
2026-02-13 10:37:23 +00:00
|
|
|
Example = Schema.array(Schema.string),
|
|
|
|
|
Ping = Schema.string,
|
|
|
|
|
Pong = Schema.string,
|
|
|
|
|
PingAll = Schema.string,
|
2026-02-13 07:58:54 +00:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
```luau [Server]
|
|
|
|
|
local Warp = require(path.to.warp).Server()
|
|
|
|
|
local Schemas = require(path.to.schemas)
|
2024-01-05 12:14:38 +00:00
|
|
|
|
2026-02-13 07:58:54 +00:00
|
|
|
-- Use schemas
|
|
|
|
|
for eventName, schema in Schemas do
|
2026-02-13 10:37:23 +00:00
|
|
|
Warp.useSchema(eventName, schema)
|
2026-02-13 07:58:54 +00:00
|
|
|
end
|
2024-01-05 12:14:38 +00:00
|
|
|
|
2026-02-13 07:58:54 +00:00
|
|
|
Warp.Connect("Example", function(player, arg)
|
2026-02-13 10:37:23 +00:00
|
|
|
print(table.unpack(arg))
|
|
|
|
|
return "Hey!"
|
2026-02-13 07:58:54 +00:00
|
|
|
end)
|
|
|
|
|
Warp.Connect("Ping", function(player, ping)
|
2026-02-13 10:37:23 +00:00
|
|
|
if ping then
|
|
|
|
|
print("PING!")
|
|
|
|
|
Warp.Fire("Pong", true, player, "pong!") -- Fire to spesific player through reliable event
|
|
|
|
|
Warp.Fire("PingAll", true, "ey!") -- Fire to all clients through reliable event
|
|
|
|
|
end
|
2024-01-05 12:14:38 +00:00
|
|
|
end)
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-13 07:58:54 +00:00
|
|
|
```luau [Client]
|
2024-01-05 12:14:38 +00:00
|
|
|
local Players = game:GetService("Players")
|
2026-02-13 07:58:54 +00:00
|
|
|
local Warp = require(path.to.warp).Client()
|
|
|
|
|
local Schemas = require(path.to.schemas)
|
2024-01-05 12:14:38 +00:00
|
|
|
|
2026-02-13 07:58:54 +00:00
|
|
|
-- Use schemas
|
|
|
|
|
for eventName, schema in Schemas do
|
2026-02-13 10:37:23 +00:00
|
|
|
Warp.useSchema(eventName, schema)
|
2026-02-13 07:58:54 +00:00
|
|
|
end
|
2024-01-05 12:14:38 +00:00
|
|
|
|
|
|
|
|
-- Connect the events
|
|
|
|
|
local connection1
|
2026-02-13 07:58:54 +00:00
|
|
|
connection1 = Warp.Connect("Pong", function(pong: boolean) -- we store the connection so we can disconnect it later
|
2026-02-13 10:37:23 +00:00
|
|
|
if pong then
|
|
|
|
|
print("PONG!")
|
|
|
|
|
end
|
2024-01-05 12:14:38 +00:00
|
|
|
end)
|
2026-02-13 07:58:54 +00:00
|
|
|
Warp.Connect("PingAll", function(isPing: boolean)
|
2026-02-13 10:37:23 +00:00
|
|
|
if isPing then
|
|
|
|
|
print("I GET PINGED!")
|
|
|
|
|
end
|
2024-01-05 12:14:38 +00:00
|
|
|
end)
|
|
|
|
|
|
2026-02-13 10:37:23 +00:00
|
|
|
task.wait(3) -- lets wait a few seconds, let the server do the things first!
|
|
|
|
|
|
2024-01-05 12:14:38 +00:00
|
|
|
-- Try request a event from server!
|
2026-02-13 07:58:54 +00:00
|
|
|
print(Warp.Invoke("Example", 1, { "Hello!", `this is from: @{Players.LocalPlayer.Name}` }))
|
2024-01-05 12:14:38 +00:00
|
|
|
-- Do a ping & pong to server!
|
2026-02-13 07:58:54 +00:00
|
|
|
Warp.Fire("Ping", true, "ping!") -- we send through reliable event
|
2024-01-05 12:14:38 +00:00
|
|
|
|
|
|
|
|
-- Disconnect All the events
|
2026-02-13 10:37:23 +00:00
|
|
|
connection1:Disconnect()
|
2026-02-13 07:58:54 +00:00
|
|
|
-- or just disconnect spesific connection
|
2026-02-13 10:37:23 +00:00
|
|
|
Warp.DisconnectAll("PingAll")
|
2024-01-05 12:14:38 +00:00
|
|
|
|
|
|
|
|
-- Destroying/Deleting a Event?
|
2026-02-13 07:58:54 +00:00
|
|
|
Warp.Destroy("Pong")
|
2024-05-29 09:58:20 +00:00
|
|
|
```
|
|
|
|
|
:::
|