dam034 Posted October 5, 2017 Share Posted October 5, 2017 Dear users, if in a resource I create many lua files, one for functions, one for variables, one for events, ecc..., are they all visible between them? If I declare a variable in a.lua, can I edit it in b.lua and output in c.lua? I need some particular declaration? Thanks Link to comment
itHyperoX Posted October 5, 2017 Share Posted October 5, 2017 players can see only "client" side script, but you can check it. go to MTA\mods\deathmatch\resources, pick any resources, and you can see it. I think you need to compile the "shared" file too. Link to comment
Moderators IIYAMA Posted October 5, 2017 Moderators Share Posted October 5, 2017 Variables are shared. Unless They are declared as locals. local localVariable Or if they are parameters. (which are also locals) function thisFunction (parameter1, parameter2) end A local variable can not leave it's block, neither it's file(which becomes it's block). http://lua-users.org/wiki/ScopeTutorial -- start file block function exampleFunction () -- start function block if true then -- start IF block -- ... -- end IF block elseif true then -- start ELSEIF block -- ... -- end ELSEIF block else -- start ELSE block -- ... -- end ELSE block end -- end function block end -- end file block -- start file block -- function exampleFunction () -- start function block if true then -- start IF block -- ... -- end IF block elseif true then -- start ELSEIF block -- ... -- end ELSEIF block else -- start ELSE block -- ... -- end ELSE block end -- end function block end -- -- end file block local variable -- I can not leave :( 2 Link to comment
koragg Posted October 6, 2017 Share Posted October 6, 2017 Functions are visible between files btw. Unless they're local. You can make one file with useful functions and then another one with the main code. You can use the functions from the first file in the main one without a problem. Link to comment
dam034 Posted October 6, 2017 Author Share Posted October 6, 2017 Thanks for the explanation I understood. Now, I want to know if a variable/function declared in a lua file is visible: in a lua file of another resource in a http file of the same resource Thanks Link to comment
koragg Posted October 6, 2017 Share Posted October 6, 2017 9 minutes ago, dam034 said: I want to know if a variable/function declared in a lua file is visible: in a lua file of another resource Only if you export it (for a function): I think variables can't be used in another resource but not sure about it. Link to comment
dam034 Posted October 10, 2017 Author Share Posted October 10, 2017 Today I have another question: if I declare a variable in a lua file executed clientside, can I read it in another lua executed serverside in the same resource? Thanks Link to comment
Moderators IIYAMA Posted October 10, 2017 Moderators Share Posted October 10, 2017 (edited) 7 minutes ago, dam034 said: Today I have another question: if I declare a variable in a lua file executed clientside, can I read it in another lua executed serverside in the same resource? Thanks As I said in my previous post. You just asked the exact same question as in your first post. Edited October 10, 2017 by IIYAMA 1 Link to comment
dam034 Posted October 10, 2017 Author Share Posted October 10, 2017 Since I don't understand good the english, can you tell me if a variable declared clientside I can (and how) read serverside? Thanks Link to comment
koragg Posted October 10, 2017 Share Posted October 10, 2017 25 minutes ago, dam034 said: Since I don't understand good the english, can you tell me if a variable declared clientside I can (and how) read serverside? Thanks You can send variables's values only via events: https://wiki.multitheftauto.com/wiki/TriggerServerEvent https://wiki.multitheftauto.com/wiki/TriggerClientEvent https://wiki.multitheftauto.com/wiki/TriggerEvent or element data: https://wiki.multitheftauto.com/wiki/SetElementData https://wiki.multitheftauto.com/wiki/GetElementData 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