Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Question

I am currently in the midst of building a larger open computers project for which i need to go through a lot of blocks with very specific labels (x-y-z, where x,y and z are integers, 0-5-99 for example), which is the only difference that can be found between the blocks without looking at them, that are stored in an ae2 Me system.

The problem: I only know the maximum values for x,y and z, but not which individual block exist. My question is now if there is a way to do a "fuzzy" search (something like "-32-" to find all items containing that string in their label) within the ae2 integration(searching for all of the blocks takes way to long(64000 blocks and more)), so far i have only come across getting all items or only items with an exactly matching label. In case there is no way to do this in the current ae2 integration i would like to request this feature.

MC 1.12.2

OC 1.7.3.146

Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0
  • Solution

Alright, so I tried to incorporate a function for exporting into the searching algorithm. It does not contain all features your code has, but I think the message and red stone stuff is not too important for the search function, I hope you'll be able to add all the stuff that I left out.

local component = require"component"
local sides = require"sides"
local event = require"event"

local database = component.database
local exportBus = component.me_exportbus
local controller = component.me_controller


local sleep = os.sleep

-- exports an item stack using the connected export bus and the database
-- @param label: lable of item (string)
-- @param side: side (number)
-- @param slot: slot number for export (number or nil, default: 1=

local function export(label, side, slot)
  slot = slot or 1
  database.clear(1)
  controller.store({label = label}, database.address, 1)
  exportBus.setExportConfiguration(side, slot, database.address, 1)
  exportBus.exportIntoSlot(side, slot)
  sleep(0)
end

-- get a table of all items in the inventory
local tbl = controller.getItemsInNetwork()

-- fuzzy search allows you to specify one or multiple variables
-- use nil for variables you don#t want to specify
-- fuzzySearch(nil, 32, nil); fuzzySearch(nil, nil, 45) etc
-- @param x: x value for label (number or nil if x shouldn t be specified)
-- @param y: y value for label (number or nil)
-- @param z: z value for label (number or nil)
-- @param side: side of inventory (number)
-- @param slot: slot number of inventory (number or nil, default: 1)

local function fuzzySearch(x, y, z, side, slot)
  local pattern = (x or '%d+')..'%-'..(y or '%d+')..'%-'..(z or '%d+')
  for _, item in ipairs(tbl) do
    local label = string.match(item.label, pattern)
    if label then
      export(label, side, slot)
    end
  end
end

local format = '%d+-%d+-%d+'

-- fuzzySearch2 uses a modified format string as input
-- you can replace one or multiple '%d+' for a real number
-- @param pattern: modified pattern (string)
-- @param side: side of inventory (number)
-- @param slot: slot of inventory (number or nil)

local function fuzzySearch2(pattern, side, slot)
  for _, items in ipairs(tbl) do
    local label = string.match(items.label, pattern)
    if label then
     export(label, side, slot)
    end
  end
end

I did not do too much testing yet since I didn't have a lot of time and since you're dealing with 3d-printers and I don't know your setup, it is kinda hard to run tests under the right conditions, so I hope it works for you.

Link to post
Share on other sites
  • 0

Hey,

I might have an idea how to solve your issue, but some more information might help. With what method you get these specific labels? I've been using OC with AE2 a couple times and I do not remember any method that provided data about stored items in that specific format. If you could tell me in what kind of data structure you have stored these labels and stuff like that, I might be able to help you.

Link to post
Share on other sites
  • 0

Alright, I guess I know now what you want to do.

I came up with some code that allows you to do some fuzzy search, just like you wanted..hopefully

local tbl = require'component'.me_controller.getItemsInNetwork()
-- tbl contains all items, from getItemsInNetwork methods 

-- fuzzy search allows you to specify one or multiple variables
-- use nil for variables you don#t want to specify
-- fuzzySearch(nil, 32, nil); fuzzySearch(nil, nil, 45) etc
-- this function currently looks for the 'name' entry in the table, you might need to change that

local function fuzzySearch(x, y, z)
  local pattern = (x or '%d+')..'%-'..(y or '%d+')..'%-'..(z or '%d+')
  for _, items in ipairs(tbl) do
    if string.match(items.name, pattern) then
      -- do stuff
    end
  end
end

local format = '%d+%-%d+%-%d+'

-- fuzzySearch2 uses a modified format string as input
-- you can replace one or multiple '%d+' for a real number
-- '%d+%-32%-%d+', '%d+%-%d+%-45', etc

local function fuzzySearch2(pattern)
  for _, items in ipairs(tbl) do
    if string.match(items.name, pattern) then
      -- do stuff
    end
  end
end

You still have the issue that you actually have to traverse all items in the ME-system, but since Lua is a fast and efficient language, that shouldn't be a problem.I did some testing and traversing a table with 125000 entries took only around 0.03 s, so that should be fine.

Hopefully this is what you were looking for and it actually helps.

Link to post
Share on other sites
  • 0

OK so i tried integrating your code into my program but very fast i noticed something: i can not download all items because the database upgrade only allows, as far as i know, 81 entries and i have way more ( i remind ~64000 items).

now that i am back at my PC i can give you my original code for going through the items:

local c = require("component")
local s = require("sides")
local event = require("event")

local db = c.database
local ex = c.proxy(c.me_exportbus.address)
local me = c.proxy(c.me_controller.address)
local r = c.redstone
local m = c.modem

args = {...}
m.open(111)
m.setStrength(64)

--z=args[2]
if args[4] then
 minz = args[4]
else
 minz = 0
end
for z=minz,args[2] do
 num = 0
 print(z)
 for x=0,args[3] do
  db.clear(1)
  l = z.."-"..args[1].."-"..(args[3]-x)..".0"
  items = me.getItemsInNetwork({label = l})
  if #items > 0 then
   me.store({label = l},db.address,1)
   print(db.get(1).label)
   ex.setExportConfiguration(5,1,db.address,1)
   ex.exportIntoSlot(5)
   os.sleep(0.1)
   num = num+1
  end
  if num == 40 then
   m.broadcast(111,z)
   os.sleep(10)
   red = r.getInput(5)
   while red == 0 do
    os.sleep(0.1)
    red = r.getInput(5)
   end
   num = 0
  end
 end
 if num > 0 then
  m.broadcast(111,z)
  os.sleep(10)
  red = r.getInput(5)
  while red == 0 do
   os.sleep(0.1)
   red = r.getInput(5)
  end
 end
end

 

Link to post
Share on other sites
  • 0

Ok, I have never worked with the database component before, so I don‘t know what its limits are. But is it really necessary to use the database? Isn‘t it enough to just use the ae2 methods and look for items‘ names? Or are the labels you set not visible for the ae2 api?

I‘m currently kinda busy, but on friday I will have some time to do some investigation using the database. I will let you know when I found a solution.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.