• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Convert String to Table

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,780
Solutions
31
Reaction score
2,299
Location
Sweden?
Hello,

Im bit stuck with something. I want to convert string to table, since attributes does not accept tables and i suck on using prefixs.

Code:
target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, ("{name = %s}, {level = %d}"):format(player:getName(), player:getLevel()))

Code:
local t = {}
target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gsub("{(.-)}", function(a) t[#t+ 1] = a end)

So i would like to split name/level as key entry and value entry. So will be able to loop like this:

Code:
for _, v in ipairs(t) do
    print(v.name, value.level)
end

Cheers.
 
Last edited:
Code:
local t = loadstring("return "..target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))()
should set the table in description to t

you can also use serialize functions (i believe mkalo posted serialize/unserialize on otland somewhere)

if you want ppl to read the string (and not just for internal uses), why not just string.match?
 
Last edited:
Back
Top