myjobisgop Posted November 20, 2013 Share Posted November 20, 2013 Hi! I found a bag of function setAccountData Let i have an array with a large number of keys (over 10 for example): BigArray = { Key1 = "Value 1", Key2 = "Value 2", Key3 = "Value 3", Key4 = {"A", "ABC", "124"}, Key5 = {{"C", "D", "1244"}, "F"}, Key6 = {"value 6"} ..... } And next I want to save that array on a player account if a player leaves the game: Note: I save that array only for registered players (not for guest) addEventHandler ("onPlayerQuit", getRootElement(), function(quitType, reason, responsibleElement) local playerAccount = getPlayerAccount(source) local BigArrayForSave = toJSON(BigArray) if (isGuestAccount(playerAccount) == false) then setAccountData(playerAccount, "SaveBigArray", BigArrayForSave) end playerAccount = nil end ) And when a player enters in a game I want to get that array from his account: addEventHandler("onPlayerLogin", getRootElement(), function(thePreviousAccount, theCurrentAccount, autoLogin) if (isGuestAccount(getPlayerAccount(source)) == false) then local lastBigArray = getAccountData(theCurrentAccount, "SaveBigArray") end end ) But now lastBigArray is shorter than the line length of BigArrayForSave: string.len(BigArrayForSave) > string.len(lastBigArray) Am I doing something wrong or is that a bug of MTA? Link to comment
xXMADEXx Posted November 20, 2013 Share Posted November 20, 2013 You are trying to get the length of a table with string.len... Use: if ( #BigArrayForSave > #lastBigArray ) then Not sure, but that could be the problem. Link to comment
myjobisgop Posted November 21, 2013 Author Share Posted November 21, 2013 If you look carefully at my code, you will see that SaveBigArray and lastBigArray have a string type. Link to comment
myonlake Posted November 21, 2013 Share Posted November 21, 2013 The internal database is not made for long values. I suggest using SQLite in this case. Not sure which MTA version you're using, but before 1.3.4 there is a low character limit on values. Nowadays it's limited to 65535. Link to comment
Spajk Posted November 22, 2013 Share Posted November 22, 2013 You cant store tables in account data. Use toJSON and fromJSON. Link to comment
myjobisgop Posted November 22, 2013 Author Share Posted November 22, 2013 Spajk, Look carefuly at my code please. I put array in account data there previously a string value, made by toJSON. Link to comment
Moderators IIYAMA Posted November 22, 2013 Moderators Share Posted November 22, 2013 But you didn't use from Json. Link to comment
TAPL Posted November 22, 2013 Share Posted November 22, 2013 The limit for setAccountData is 128, that's why you have trouble with toJSON and fromJSON. You need to find other way to store the string, like SQLite or XML or even a file. Link to comment
Spajk Posted November 23, 2013 Share Posted November 23, 2013 Spajk, Look carefuly at my code please. I put array in account data there previously a string value, made by toJSON. oh, sorry 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