poncianux Posted December 22, 2010 Share Posted December 22, 2010 Hey there, this is my first post. I want to know if LUA can globalize variables through resources. Example: **You have one variable on a clientside/serverside resource called R1 wich contains his own meta.xml and one LUA file script.lua In script.lua you have the next variable: local XL3 = "Content" local LX10 = 0 **You have other resource with the same description but name: R2 His LUA file named file.lua In file.lua you want to use the variable "XL3" and "LX10" from R1 on R2 if (XL3 == "Content") then LX10 = 1 ++My point is simple, not so complicated like this, but want to know if in this script language is possible On VB.net to use global variables you can declare them on a Module On C# to use global variables you must call the variable from file and specify their use (rw) Hope you can help me! Thanks Link to comment
Castillo Posted December 22, 2010 Share Posted December 22, 2010 i did a fast try, inserted lol = "testing then did a cmd in another resource and returns "nil" Link to comment
poncianux Posted December 22, 2010 Author Share Posted December 22, 2010 That is pretty obvious if you dont specify where does the variable comes from! I need to know that! Thanks for reply Link to comment
Castillo Posted December 22, 2010 Share Posted December 22, 2010 A friend tells me that is not possible to call them from other resources. You can pass values with exported functions. Link to comment
poncianux Posted December 22, 2010 Author Share Posted December 22, 2010 What exactly I want is to retreive money, wins, age, etc of a player from a resource that have those values to put them on scoreboard, but I dont want that the addScoreboardColumn function had to be on the same resource! Link to comment
Castillo Posted December 22, 2010 Share Posted December 22, 2010 you can use setElementData, getElementData. https://wiki.multitheftauto.com/wiki/SetElementData https://wiki.multitheftauto.com/wiki/GetElementData Link to comment
izstas Posted December 22, 2010 Share Posted December 22, 2010 Each resource runs in own Lua VM (AFAIK), so global variables is available only inside the resource. Link to comment
Arran Posted December 22, 2010 Share Posted December 22, 2010 Better than element data: exports You can use an exported function to return a variable. local somevar = 1000000 function getSomeVariable() return somevar end And in the meta.xml just add: Then call it like: exports.resourceNameHere:getSomeVariable() Link to comment
Castillo Posted December 22, 2010 Share Posted December 22, 2010 yeah, i know that exported functions can be used too for this, but i was trying tell easiest way Link to comment
poncianux Posted December 22, 2010 Author Share Posted December 22, 2010 If both ways has same result I think I will use the export method, thank you all for your help! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now