Th3Angel Posted February 5, 2012 Share Posted February 5, 2012 (edited) Evening everyone, I have a few quick questions for anyone that wants to help me. How exactly do functions and variables "communicate" with each other between the server and client. For example, if I have a function in a clientside script, will I be able to access that same function on the server? Does the same thing apply for serverside script? What if I try to access that function from the clientside script in another clientside script and vice versa, will that be possible? What about variables in the same scenario? I'm asking this because I've noticed that Lua has "local" functions and I've seen some scripts where variables are used but not declared, such as "variable1 = variable2" when 'variable2' was nowhere to be found inside the script. Thanks for sparing your time! Edited February 5, 2012 by Guest Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 Evening everyone, I have a few quick questions for anyone that wants to help me.How exactly do functions and variables "communicate" with each other between the server and client. For example, if I have a function in a clientside script, will I be able to access that same function on the server? The same thing for serverside scripts? What if I try to access that function from the clientside script in another clientside script and vice versa, will that be possible? Thanks for sparing your time! First:you need use setElementData or triggerClientEvent/ triggerServerEvent or https://wiki.multitheftauto.com/wiki/CallClientFunction or https://wiki.multitheftauto.com/wiki/CallServerFunction . What about variables in the same scenario? I'm asking this because I've noticed that Lua has "local" functions and I've seen some scripts where variables are used but not declared, such as "variable1 = variable2" when 'variable2' was nowhere to be found inside the script. Second. do local a = 100 do local g = 5 local s = g outputChatBox( '--> '..tostring( g ) ) --> 5 outputChatBox( '--> '..tostring( s ) ) --> 5 local n = 6 local a = 101 outputChatBox( '--> '..tostring( a ) ) --> 101 end outputChatBox( '--> '..tostring( a ) ) -- > 100 outputChatBox( '--> '..tostring( n ) ) --> nil end http://www.lua.org/manual/5.1/manual.html#2.6 You mean it? Link to comment
Th3Angel Posted February 5, 2012 Author Share Posted February 5, 2012 I'm not referring to lexical scopings, I'm asking how scripts share information between each other such as functions and variables. But thanks for informing me of clientside-serverside and serverside-clientside communication! Let's use 50p's GUI Classes for example. No functions are exported, you only have to include the lua file in meta.xml to use the functions of the different gui classes. So if one function exists in a clientside script, can I use that same function inside another clientside script? Do the same rules apply for serverside scripts? Will this also work with variables? Link to comment
Castillo Posted February 5, 2012 Share Posted February 5, 2012 You can use a function from another script file of the same resource, as long as both script's are of the same type (client and server side). But if you make the function local, you won't be able to use it. Link to comment
Th3Angel Posted February 5, 2012 Author Share Posted February 5, 2012 Aah, ok. So the same applies for variables too? Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 Aah, ok. So the same applies for variables too? Yes. Link to comment
Th3Angel Posted February 5, 2012 Author Share Posted February 5, 2012 Ok. Thanks Kenix and Solidsnake14 for sparing your time and helping me! 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