Very confused about where to store persistent server side variables

So I went through the tutorials and have the demo. but I’m really stuck here and can’t find any clear answer in the documentation.

I’m simply trying to store 1 boolean (isOpen) on the server (this var represents a door being either closed or open in my game) and have an RPC that toggles this from true to false.

I’m using LUA and this variable reset each time the RPC is called. where can I store this so it saves the state of this door?

Hi @Mobislick,
Welcome to Nakama community,
This depends on how often you change the boolean variable status.
You can consider using

1. Authoritative Multiplayer

where you can save the door open/close status on the state table
function M.match_loop(context, dispatcher, tick, state, messages)
   state.isDoorOpen = true -- Make the door open 

2. Collections

You can also use the collection to save the status of the door and make the proper permission to control who can read/write

  • ReadPermission can have “Public Read” (2), “Owner Read” (1), or “No Read” (0).
  • WritePermission can have “Owner Write” (1), or “No Write” (0).

then you can use RPC calls to check if a person can change the status

But Its recommended to use the first method, but it depends on your idea and what you want to do exactly.

Avoid using global lua variables

1 Like