Jump to content

Communication of Functions and Variables


Th3Angel

Recommended Posts

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 by Guest
Link to comment
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

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

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...