Jump to content

Use a variable in different resources


TheCapn

Recommended Posts

Hello,

I'm using a table named plrMpState and I would like to use it in two differents resources : wrCommon and wrChat

Actually, my table is declared at the very beggining of the file init.lua in the wrCommon resource, and I would like to use it in the mp.lua file in the wrChat resource.

Could you explain me how to manage it ?

Regards,

Link to comment

You can export functions. Just return your table like, pretend the resource is called 'wrCommon':

  
plrMpState = { "something" } 
  
function exportTable( value ) 
  
    if not value then 
        return plrMpState 
    else 
        return plrMpState[ value ] 
    end 
    return false 
  
end 

Put this into your meta.xml:

  
<export function="exportTable" type="client"/> 
<export function="exportTable" type="server"/> 

To get your values from the table use this in your scripts:

 plrMpState = exports.wrCommon:exportTable() 

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...