Skip to content

Example 1.1

Let's try and play something with Warp!

luau
local Schema = require(path.to.warp).Buffer.Schema

return {
	Example = Schema.array(Schema.string),
	Ping = Schema.string,
	Pong = Schema.string,
	PingAll = Schema.string,
}
luau
local Warp = require(path.to.warp).Server()
local Schemas = require(path.to.schemas)

-- Use schemas
for eventName, schema in Schemas do
	Warp.useSchema(eventName, schema)
end

Warp.Connect("Example", function(player, arg)
	print(table.unpack(arg))
	return "Hey!"
end)
Warp.Connect("Ping", function(player, ping)
	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
end)
luau
local Players = game:GetService("Players")
local Warp = require(path.to.warp).Client()
local Schemas = require(path.to.schemas)

-- Use schemas
for eventName, schema in Schemas do
	Warp.useSchema(eventName, schema)
end

-- Connect the events
local connection1
connection1 = Warp.Connect("Pong", function(pong: boolean) -- we store the connection so we can disconnect it later
	if pong then
		print("PONG!")
	end
end)
Warp.Connect("PingAll", function(isPing: boolean)
	if isPing then
		print("I GET PINGED!")
	end
end)

task.wait(3) -- lets wait a few seconds, let the server do the things first!

-- Try request a event from server!
print(Warp.Invoke("Example", 1, { "Hello!", `this is from: @{Players.LocalPlayer.Name}` }))
-- Do a ping & pong to server!
Warp.Fire("Ping", true, "ping!") -- we send through reliable event

task.wait(1) -- lets wait for a second!

-- Disconnect All the events
connection1:Disconnect()
-- or just disconnect spesific connection
Warp.DisconnectAll("PingAll")

-- Destroying/Deleting a Event?
Warp.Destroy("Pong")