DiSaMe Posted June 26, 2009 Share Posted June 26, 2009 I have just decided that using element data functions would be better than array of players data. And some of data is in array format too. So I have to do something like this with element data. This is what I tried with runcode resource: setElementData(player,"array",{4,5,6}) Then checked it: getElementData(player,"array")[2] It returned 5. It's OK. Now here's the problem. I try to change one field in array: getElementData(player,"array")[3] = 7 But when I use getElementData(player,"array")[3] it still returns 6. Is there any way to use element data as array? Link to comment
robhol Posted June 26, 2009 Share Posted June 26, 2009 While storing arrays will obviously work, I suspect the reason for this problem is that, when getElementData'ing it, you get an actual array instead of a pointer to it. (Which makes sense since element data is supposed to be synchronized between server and clients and pointers of any kind would be a bad idea.) After setting the value, you will need to setElementData the resulting array back into the element data. Link to comment
darkdreamingdan Posted June 26, 2009 Share Posted June 26, 2009 In that sense, storing arrays that get updated constantly is probably largely inefficient. To update a single value you have to send a completely new table. Link to comment
Lordy Posted June 27, 2009 Share Posted June 27, 2009 Also if you don't need them to be synced, using tables to store data is better than element data. Something about bandwidth I think, since element data is synced with clients and server. Link to comment
DiSaMe Posted June 27, 2009 Author Share Posted June 27, 2009 Yes, I know that, but some of the data has to be synced with clients. Right now my gamemode uses triggerClientEvent for that. But if using element data is so inefficient, maybe I'll stay with tables. I think I don't need to sync player inventory with all clients just because he bought one more item when he already has 50 items and he must see them all in his inventory window Link to comment
DiSaMe Posted June 27, 2009 Author Share Posted June 27, 2009 (edited) Because I don't want to create thousands of topics, I'll tell you about my another problem here. a = 5*1e-005 outputChatBox(tostring(a)) When executed server-side, it outputs 5e-005. In client-side it shows 4.9999998736894e-005. How could I make it be shown correctly? Edited November 7, 2009 by Guest Link to comment
50p Posted June 27, 2009 Share Posted June 27, 2009 Because I don't want to create thousands of topics, I'll tell you about my another problem here. a = 5*1e-005 outputChatBox(tostring(a)) When executed server-side, it outputs 5e-005. In client-side it shows 4.9999998736894e-005. How could I make it be shown correctly? I don't like it when I have 256mg of amphetamine but in kilograms it shows 0.00025599999935366... This is an issue with sending large numbers to client. I had the same problem with my bank resource which doesn't always show correct amount of money you have on your account because sending huge numbers to client fails. This is from changelog of the bank resource: * fixed: The difference between 99999999 and (the total of pocket money + money to withdraw) could be lost. That would make you lose money if you wanted to withdraw more, this is caused by GTA itself because you can only have 99,999,999 at a time. Although, sometimes your account balance (in GUI window) may not be shown correctly because the amount to be displayed isn't sent correctly to the client. Link to comment
DiSaMe Posted June 28, 2009 Author Share Posted June 28, 2009 My problem isn't about sending data to client. The code I just wrote returns incorrect result and is completely client-side. In my gamemode I have 256mg amphetamine in the inventory. This number is sent from server and displayed correctly with GUI. But where it shows the mass in kilograms, it multiplies those 256mg by 0.000001 (which is stored in client-side) and displays 0.00025599999935366. Link to comment
robhol Posted June 28, 2009 Share Posted June 28, 2009 Out of curiosity, did you try dividing it instead of multiplying it? I'm not sure if it helps, but it seems like a fairly easy thing to test before moving on to more exotic solutions... Link to comment
DiSaMe Posted June 28, 2009 Author Share Posted June 28, 2009 Yes, I just divided it and it's still the same. By the way, I just noticed that even dividing 256 by 10 or multiplying by 0.1 returns 25.60000038147. Link to comment
darkdreamingdan Posted July 5, 2009 Share Posted July 5, 2009 This is due to floating point inaccuracies, which happens due to the fact that MTA has to interpret the data when you use an MTA function. You may want to consider using tables instead, or storing it as a string as robhol suggested. 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