selectory2 = 18
currentitem = 1
itemscreen1 = Image.load("./misc/itemscreen-1.png")
itemscreen2 = Image.load("./misc/itemscreen-2.png")
itemscreen3 = Image.load("./misc/itemscreen-3.png")
while itemlist > 0 and turn == 0 do
screen:clear()
pad = Controls.read()
if itemlist == 1 then
	counter = counter + 1
	screen:blit(0, 0, itemscreen1)
	screen:blit(180, selectory2, selector)
	for itemblit = 1,2 do
	screen:print(items[itemblit].x, items[itemblit].y,items[itemblit].name  .. "     x" ..items[itemblit].amount)
	end
	if pad:right() and oldpad:right() ~= pad:right() then
		itemlist = 3
	end
	if pad:down() and oldpad:down() ~= pad:down() and selectory2 < items[1].y then
		selectory2 = selectory2 + 23
		currentitem = currentitem + 1
	end
	if pad:up() and oldpad:up() ~= pad:up() and selectory2 > items[1].y then
		selectory2 = selectory2 - 23
		currentitem = currentitem - 1
	end
	if pad:l() then
		screen:clear()
		itemlist = 0
	end
	if pad:r() and oldpad:r() ~= pad:r() and items[currentitem].amount > 0 and counter > 5 then
	dofile("./items/" .. items[currentitem].name .. ".lua") 
	turn = 1
	end

end

if itemlist == 3 then
screen:blit(0, 0, itemscreen3)
	screen:blit(180, selectory2, selector)
	for ballblit = 1, 2 do
	screen:print(pokeballs[ballblit].x,pokeballs[ballblit].y,pokeballs[ballblit].name .. "     x" .. pokeballs[ballblit].amount)
	end
	if pad:left() and oldpad:left() ~= pad:left() then
		itemlist = 1
	end
	if pad:down() and oldpad:down() ~= pad:down() and selectory2 < pokeballs[1].y then
		selectory2 = selectory2 + 23
	end
	if pad:up() and oldpad:up() ~= pad:up() and selectory2 > pokeballs[1].y then
		selectory2 = selectory2 - 23
	end
	if pad:l() then
		screen:clear()
		itemlist = 1
	end
	if pad:r() and oldpad:r() ~= pad:r() and pokeballs[currentitem].amount > 0 then
		a = "pokecatch"
		itemlist = 0
		screen:clear()
		dofile("./items/" .. pokeballs[currentitem].name .. ".lua") 
		
		
	end
end
screen.waitVblankStart()
screen.flip()



oldpad = pad
end