mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Adjust how synced vars work.
This commit is contained in:
parent
e92de6829d
commit
ad1a4972f0
1 changed files with 3 additions and 2 deletions
|
@ -41,19 +41,20 @@ function rpc_base:create_var(name, cb_fn)
|
||||||
local var = {}
|
local var = {}
|
||||||
local rpc_name = "_set_var_"..name
|
local rpc_name = "_set_var_"..name
|
||||||
var.values = {}
|
var.values = {}
|
||||||
|
var.prev_values = {}
|
||||||
self.opts_reliable()
|
self.opts_reliable()
|
||||||
self.opts_everywhere()
|
self.opts_everywhere()
|
||||||
self[rpc_name] = function(new_value)
|
self[rpc_name] = function(new_value)
|
||||||
|
var.prev_values[ctx.rpc_peer_id] = var.values[ctx.rpc_peer_id]
|
||||||
|
var.values[ctx.rpc_peer_id] = new_value
|
||||||
if cb_fn ~= nil then
|
if cb_fn ~= nil then
|
||||||
cb_fn(new_value)
|
cb_fn(new_value)
|
||||||
end
|
end
|
||||||
var.values[ctx.rpc_peer_id] = new_value
|
|
||||||
end
|
end
|
||||||
local set_rpc = self[rpc_name]
|
local set_rpc = self[rpc_name]
|
||||||
function var.set(new_value)
|
function var.set(new_value)
|
||||||
if new_value ~= var.values[ctx.my_id] then
|
if new_value ~= var.values[ctx.my_id] then
|
||||||
set_rpc(new_value)
|
set_rpc(new_value)
|
||||||
var.values[ctx.my_id] = new_value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ctx.add_hook("on_should_send_updates", "net_vars", function()
|
ctx.add_hook("on_should_send_updates", "net_vars", function()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue