[ create a new paste ] login | about

Link: http://codepad.org/EcwaoRhz    [ raw code | output | fork ]

Lua, pasted on Aug 24:
function copy(tab)
    local ret = {}
    for _,v in pairs(tab) do 
        table.insert(ret, v)
    end
    return ret
end

function sortPokemonsArray(pokemons)
	math.randomseed(os.time())
	local used = copy(pokemons)
	local sortedPokes = {}
    	
	for i = 1, #pokemons do
		local i= math.random(#used)
    		table.insert(sortedPokes, used[i])
    		table.remove(used, i)
    		used = copy(used)
	end
	return sortedPokes
end

local pokemons = {
	{name = "Vaporeon", level = 250, nick = "", ball = "normal"},
	{name = "Gyarados", level = 300, nick = "", ball = "normal"},
	{name = "Tentacruel", level = 320, nick = "", ball = "normal"},
	{name = "Golduck", level = 330, nick = "", ball = "normal"},
	{name = "Blastoise", level = 350, nick = "", ball = "normal"},
	{name = "Starmie", level = 400, nick = "", ball = "normal"},
} 

local sorted = sortPokemonsArray(pokemons)

-- string serializada
local sorted_str = table.serialize(sorted)

-- table unserialize
local pokes = table.unserialize(sorted_str)


Output:
1
2
3
4
line 35: attempt to call field 'serialize' (a nil value)
stack traceback:
	t.lua:35: in main chunk
	[C]: ?


Create a new paste based on this one


Comments: