Jump to content

Variables global to both server and client


Ayanami

Recommended Posts

Hello folks,

I have an issue with the validity range of variables.

When I create a global variable inside a server script and then try to access / output it within a client script, it's always nil. Unfortunately I couldn't find any proper documentation on this, so I am asking you: Is that the normal behaviour of a global variable? If so, how to transfer it to the client side anyways? I have weird approaches in my mind about setElementData("console", ...), but I do not really believe that this is how the problem is to be fixed the best way.

Thanks for your assistance in advance.

Link to comment

Yes. Global variables aren't truly global (for obvious reasons. Imagine the chaos! :P) but are common between all server-side script files in a resource, and all client-side script files. But not from server to client or vice-versa.

You will either have to use element data or transfer the data with events. I recommend reading my Basics of Scripting guide. It's a sticky in this forum.

Link to comment

This hurts a little. I guess then I just dump all data to the Console element and hope, no resource ever needs it being restarted. Though this makes it necessary that every function (server and client) needs to do a ReadData() as a first step and a WriteData() when finished. Still, it's...messy @_@

Anyways, thanks for the quick and enlightening response :)

Link to comment

To put it shorlty, I try to create some kind of Ped creator / editor. Since my programming knowledge derives not from Lua but from other major languages which are a little different, my first approach was to store all Ped data into rather complex arrays (e.g. pedtable[3]["firstname"] would return the first name of Ped with my ID 3). But now I must admit that just attaching the data to the respective Ped with SetElementData ist probably the far better solution. I've got a couple of other variables to store and eventually transfer to client scripts though (e.g. I also work on a possibilty to define walking routes for Peds, which are atm also stored in an array in the form of routetable[4][12]["X"] = Route 4, Checkpoint 12, X coordinate. Since multiple Peds should be able to use the same route, I do not want to attach the route to a certain Ped. But I'll hopefully come up with a solution for that...

Thanks for your input again.

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