From 6759f43dc967cdeb04713cb69e97292eefc7d14d Mon Sep 17 00:00:00 2001
From: ubq323 <ubq323@ubq323.website>
Date: Thu, 12 Jan 2023 18:15:24 +0000
Subject: shop2

---
 shop2/disp.lua  | 10 +---------
 shop2/items.lua |  4 ++--
 shop2/main.lua  |  6 +++++-
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/shop2/disp.lua b/shop2/disp.lua
index eb06625..570e2d6 100644
--- a/shop2/disp.lua
+++ b/shop2/disp.lua
@@ -43,13 +43,6 @@ local function disp_shopscreen(items)
 	-- 123456789012345678901234567890123456789012345678901234567
 	-- 0        1         2         3         4         5
 
-	-- sort alphabetically by address
-	-- todo: more intuitive sort, once more things are for sale
-	local adrs = {}
-	for adr in pairs(items) do table.insert(adrs,adr) end
-	table.sort(adrs)
-
-
 	-- took stock before clear, to avoid flickering
 	mon.clear()
 	mon.setTextScale(1)
@@ -69,8 +62,7 @@ local function disp_shopscreen(items)
 			{22,y}, colour, idesc.hname,
 		}
 	end
-	for ix,adr in ipairs(adrs) do
-		local idesc = items[adr]
+	for _,idesc in ipairs(items) do
 		local amt = stock.amt_of(si,idesc)
 		fmt_row(ix+2, idesc,amt)
 	end
diff --git a/shop2/items.lua b/shop2/items.lua
index 82d0104..5f612b7 100644
--- a/shop2/items.lua
+++ b/shop2/items.lua
@@ -1,8 +1,8 @@
 local items = {}
 local function i(adr,itname,hname,price,colour,check)
-	items[adr]={itname=itname,hname=hname,price=price,adr=adr,colour=colour or colors.white,check=check}
+	table.insert(items,{itname=itname,hname=hname,price=price,adr=adr,colour=colour or colors.white,check=check})
 end
-i("dmn","minecraft:diamond","Diamond",2,colors.cyan)
+i("dmn","minecraft:diamond","Diamond",1,colors.cyan)
 i("blz","minecraft:blaze_rod","Blaze Rod",0.5,colors.yellow)
 i("ely","minecraft:elytra","Elytra",100,colors.purple)
 i("mnd","minecraft:enchanted_book","Mending Book",10,colors.green,function(idetail)
diff --git a/shop2/main.lua b/shop2/main.lua
index 1def219..0a70396 100644
--- a/shop2/main.lua
+++ b/shop2/main.lua
@@ -45,10 +45,14 @@ local function proctrans(tr)
 	local function refund() if meta['return'] then sendws { type="make_transaction", to=meta['return'], amount=tr.value } end end
 
 	local mtn = tr.sent_metaname
-	local idesc = items[mtn]
+	local idesc
+	for _,i in ipairs(items) do
+		if i.adr = mtn then idesc = i end
+	end
 	if not idesc then
 		-- some other metaname that has nothing to do with us
 		-- presumably some other service @ac.kst. so just ignore it
+		print("(debug) don't know what '"..mtn.."' means, ignoring")
 		-- tell("(debug) i didn't recognise that metaname so no transaction occurs")
 		return
 	end
-- 
cgit v1.2.3