Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test123
function dump (tbl, indent) if not indent then indent = 0 end local toprint = string.rep(" ", indent) .. "{\r\n" indent = indent + 2 for k, v in pairs(tbl) do toprint = toprint .. string.rep(" ", indent) if (type(k) == "number") then toprint = toprint .. "[" .. k .. "] = " elseif (type(k) == "string") then toprint = toprint .. k .. "= " end if (type(v) == "number") then toprint = toprint .. v .. ",\r\n" elseif (type(v) == "string") then toprint = toprint .. "\"" .. v .. "\",\r\n" elseif (type(v) == "table") then toprint = toprint .. dump(v, indent + 2) .. ",\r\n" else toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n" end end toprint = toprint .. string.rep(" ", indent-2) .. "}" return toprint end local items = { bandage = 2, bow = 4, gold = 1 } local total_rate = 0 for k, v in pairs(items) do total_rate = total_rate + v end local rates = {} for k, v in pairs(items) do rates[#rates + 1] = {id = k, rate = v / total_rate} end for k = 2, #rates do if k ~= 1 then rates[k].rate = rates[k - 1].rate + rates[k].rate end end print(dump(rates))
run
|
edit
|
history
|
help
0
Lua Timer
Lua Angle Cheatsheet
multiline string
Beispiel2
missing element
Testingassets
Visala Test
lua5.3: ...Desktop/rextester_linux_2.0/usercode/68368288/source.lua:166: unexpected symbol near '}'
Random number generation with ranges (Lua)
Eliminatoria minigame