Sign in to follow this  
Dreft

Variables on different scripts.

Recommended Posts

I have:

scriptone.lua - server side

scripttwo.lua - client side

In server side script "scriptone.lua" i created variable

a = 5

How to know what "a" is equal in client side script "scripttwo.lua" ?

I mean, how to move variables through all same resource scripts ?

Share this post


Link to post

It's easy to get them in another server-side script. Synching client-side though can pretty much only be done with triggerClientEvent/triggerServerEvent or setElementData. (imagine the bandwidth usage if every single var that has changed was synched :P)

Share this post


Link to post
It's easy to get them in another server-side script.

Uhm.. ok, how to get it in another server-side script ? If i set a = 5, then in others server-side scripts its automatically set to 5 too ?

Share this post


Link to post
If i set a = 5, then in others server-side scripts its automatically set to 5 too ?

Yup

Script 1:

a=5

Script 2:

outputDebugString(tostring(a))

Output:

INFO: 5

Share this post


Link to post

Oh, easy. Thanks for help ;)

And one more question on topic :}

Script 1:

setElementData( thePlayer, "variable.a", 5 )

Script2:

a = getElementData( thePlayer, "variable.a" )

This will be right ?

Share this post


Link to post

can callClientFunction be a good alternative to triggerClientEvent?

Share this post


Link to post

Only vars in different resources or defined with "local" aren't shared. I'm pretty much sure of that yes.

Share this post


Link to post

its true, but i think this is not what he meant. it sounds much more like he wanted to know if two separate resources can share cvariables... which would be CHAOS :P

SO: Serverside global variables can be reached within this single resource, no matter if you used two different files in your resource, but wont be existing in other resources.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.