Bridges (LEGACY)#
Danger
This page contains documentation for a legacy feature available from v1.0.0 to v1.0.3. If you are new to Volt it is recommended you use the more recent and maintained version of Bridges
Bridges replace the need for RemoteFunctions and RemoteEvents in Volt. They are used to communicate client -> server and server -> client.
Creating a Bridge#
Bridges are created within executables.
SomeExecutable.Server
local MyExe = { Name = 'MyExe', Async = false }
local function RegisterBridges()
MyExe.Volt.RegisterBridge('MyBridge', function(player)
print('From client to server!')
end)
end
function MyExe.OnExecute()
RegisterBridges()
end
return MyExe
SomeExecutable.Client
local MyExe = { Name = 'MyExe', Async = false }
function MyExe.OnExecute()
MyExe.Volt.GetBridge('MyBridge'):Fire()
end
return MyExe
SomeExecutable.Server
local MyExe = { Name = 'MyExe', Async = false }
local someBridge
local function RegisterBridges()
someBridge = MyExe.Volt.RegisterBridge('MyBridge')
end
function MyExe.OnExecute()
RegisterBridges()
--[[
Later in your executable, once you've ensured the client has executed,
you can call the :Fire() method on the bridge
E.g.
someBridge:Fire()
]]
end
return MyExe
SomeExecutable.Client
local MyExe = { Name = 'MyExe', Async = false }
function MyExe.OnExecute()
MyExe.Volt.GetBridge('MyBridge'):Hook(function()
print('From server to client!')
end)
end
return MyExe
Warning
All bridges must be registered on the server. The client does not have access to the RegisterBridge
function.
Organizing Bridges#
Staying organized with your bridges is important. That's why bridges use a similar directory system to Volt's import function. Bridges are placed within Volt in a folder that is generated upon server start called Bridges
. When you create a bridge and provide it a name you can actually provide a directory to create for it too. If the directory already exists it will simply use that directory rather than creating another one.
--- Bridges
----- SomeBridges
-------- MyBridge
MyExe.Volt.RegisterBridge('MyExe/SomeBridges/MyBridge')
Tip
Bridges are not bound to their executables. You can get and use a bridge from another executable!