Need to share a variable from one script with others

Hi there everyone,

I need to share a language variable from a framework resource to all the child resources so they know what language to use. I can’t seem to sort out how to do that though.

If I’ve created a var named globalLang, how would I share that with files throughout other resources?

You could use exports. Exports work as a function that can be called from other resources, as long as they are exported. See this:

Thanks for your help, faxes.

If I added this to the server file of the resource with the variable I need to share:

exports("globalLang", function()
    return Config.Language
end)

Would I just use something like this to retrieve the var in any other resource, client or server-sided?

language = globalLang

?

See the second link. That one’s for Lua.

I was able to print the statement using the link you provided(thanks!) but I’m having problems passing a variable via that method. Instead of printing in the function, I tried:

exports('globalLocale', function()
    globalLanguage = Config.Language
end)

or

globalLanguage = Config.Locale
exports('globalLocale', function()
    return globalLanguage
end)

but when I try this to print it in another resource:

exports.framework:globalLocale()
print(globalLanguage)

It prints nil.

How do I retrieve a variable containing my language value from the export?

Got it sorted:

Config.Locale = exports.framework:globalLocale()
1 Like