Jump to content

Problem with the exchange of data


Phat Looser

Recommended Posts

Hi gaize, I have a small problem.

Its about the exchange of data between two running scripts, let me call the one "Script A" and the other "Script B".

As you already know, it is not the intention of LUA that one script is able to access variables of the other.

When I have a global variable "Pizza" in A, and a global variable "Pizza" in B, it may look the same, but they are different, and are supposed to be independent from each other. I am not common with the concept of lua, since everything just descripes how to script things (something i definitely do NOT care about, learning the syntax is a matter of hours, so its no work at all), and does not descripe how things actually work (i.e., how lua stores the variables - is it a tree or something?).

Now, to put things short:

I want a variable, which is accessable from outside the script.

I already experimented with exporting functions, and such things, and I found out that every time you include one of that exported functions into your script, it saves the variables in a different location again. So just creating a script called "share", exporting the functions in share, and calling the (same) variables with script A and B still does give me different values.

Now, back to my question:

Is there any possibility, except using the players and the function to attach variables to players (I think it was "setElementData"), to share variables?

The problem I have with "setElementData" is, that its not only shared with ALL clients, its also almost extremely slow compared to "serverside only" variables.

Link to comment

Intra-resource variables work nicely, that is, if you have a resource with two script files a.lua and b.lua, and have a.lua define a variable named CAKE, you can read that from the other file in the resource.

Inter-resource is more tricky, but you could make a separate resource to keep track of inter-resource variables, then hook it up with exported functions or events.

Link to comment
Hi gaize, I have a small problem.

Its about the exchange of data between two running scripts, let me call the one "Script A" and the other "Script B".

As you already know, it is not the intention of LUA that one script is able to access variables of the other.

When I have a global variable "Pizza" in A, and a global variable "Pizza" in B, it may look the same, but they are different, and are supposed to be independent from each other. I am not common with the concept of lua, since everything just descripes how to script things (something i definitely do NOT care about, learning the syntax is a matter of hours, so its no work at all), and does not descripe how things actually work (i.e., how lua stores the variables - is it a tree or something?).

Now, to put things short:

I want a variable, which is accessable from outside the script.

I already experimented with exporting functions, and such things, and I found out that every time you include one of that exported functions into your script, it saves the variables in a different location again. So just creating a script called "share", exporting the functions in share, and calling the (same) variables with script A and B still does give me different values.

Now, back to my question:

Is there any possibility, except using the players and the function to attach variables to players (I think it was "setElementData"), to share variables?

The problem I have with "setElementData" is, that its not only shared with ALL clients, its also almost extremely slow compared to "serverside only" variables.

Why would you need to "share" the same variable in 2 seperate resources? Make one resource and deal with with one variable.

Link to comment
Intra-resource variables work nicely, that is, if you have a resource with two script files a.lua and b.lua, and have a.lua define a variable named CAKE, you can read that from the other file in the resource.

Inter-resource is more tricky, but you could make a separate resource to keep track of inter-resource variables, then hook it up with exported functions or events.

Not working, as I explained before, the function of the external resource called in script resource A and the function called in resource B give back different values.

Why do I want to do this?

Because my last anticheat script failed due to this stupid fact that different resources are not able to exchange data, no matter what.

Why do I want to have different resources, instead of one script which contains everything?

Because of the advantage that you can change and restart a script without messing with the whole concept.

P.S.:

Don't tell me the only way to exchange such data is an SQL access.

I actually want to prevent any sort of ammo and hp hacks.

Doing so via SQL is, in my eyes, a stupid idea.

Link to comment
Intra-resource variables work nicely, that is, if you have a resource with two script files a.lua and b.lua, and have a.lua define a variable named CAKE, you can read that from the other file in the resource.

Inter-resource is more tricky, but you could make a separate resource to keep track of inter-resource variables, then hook it up with exported functions or events.

Not working, as I explained before, the function of the external resource called in script resource A and the function called in resource B give back different values.

Why do I want to do this?

Because my last anticheat script failed due to this stupid fact that different resources are not able to exchange data, no matter what.

Why do I want to have different resources, instead of one script which contains everything?

Because of the advantage that you can change and restart a script without messing with the whole concept.

P.S.:

Don't tell me the only way to exchange such data is an SQL access.

I actually want to prevent any sort of ammo and hp hacks.

Doing so via SQL is, in my eyes, a stupid idea.

If you don't want to use setElementData then you can use events, like trigger event to "ask" another resource to trigger another event to tell the resource that asked what the value is, but that's non-sense because elements can store data pretty easily, that's what it is for.

Link to comment

If you don't want to use setElementData then you can use events, like trigger event to "ask" another resource to trigger another event to tell the resource that asked what the value is, but that's non-sense because elements can store data pretty easily, that's what it is for.

Obviously, the data given to the elements is shared with the clients. Thats a do-not-want.

To trigger and to trigger back might be a possibility, but somewhat it happens when you trigger an event from one resource and then trigger it from another, two different values are "called back", depending on the values the scripts gave that "callback script" before.

I'll rescript the script I made from scratch, using triggers and trying to find out what happens. Maybe I made a mistake.

setElementData works cross-resource.

http://development.mtasa.com/index.php? ... lementData

I asked: "Is there any possibility, except using the players and the function to attach variables to players (I think it was "setElementData"), to share variables?"

Obviously, the data given to the elements is shared with the clients. Thats a do-not-want.

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