Global Variables-If Collection Is Changed Are Globals Still Available?

Hi,

Let’s say we have some global variables in one collection.
If we switch collections, are the globals still available to current collection?
Thanks!

J.

4 Likes

You should store data you want to be persistent in shared modules instead.

local data = require("datastore") -- datastore is a .lua file in the root of the project in this example
data.score = 888
print(data.my_shared_value)
local M = {}
M.my_shared_value = 777
return M

Then if you have script -> shared state checked in your game.project file this data

4 Likes