Shared Variables across multiple Resources


since the resources are run in a sandboxed environment created by <serverdir>/system/resource_init.lua (at least it seems so), I was wondering whether one is able to inject values into the global table and thus have multiple resources share the same reference to a table.

I am asking because I was trying to create a script that manages some data and also saves it to a file. But this obviously doesn’t work, because each resource requiring that script will create its own instance of it.

Thanks in advance!

First of all, there’s a difference between client and server LUA environments, so you should probably specify which one you are talking about. Judging by that you want to save a file, I take it you are talking about server-sided LUA though.

The __resource.lua exports directive and the likes is only for client scripts. For the server unfortunately there’s no such thing. But registered events are all global, so you can definitely do some magic with that.

Yes, sorry, I was talking about the server-side and I’m aware that the exports directive only works for client side scripts.
Anyways, I guess I can still go the dirty way and make the built-in files load some custom stuff.

Thanks for your answer!

Any updates on this? Since export is now possible on server side I was hoping it would work. I would like to change a variable in another resource without separately creating set functions and exporting them one by one. I tried exporting the namespace and setting the variable but it’s only one way, if I change the variable from resource B (like this: resource_a().variable = something where resource_a() returns the namespace from resource_a, being the only export I would need) it won’t actually change the variable in resource A.