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

CptMercury

Members
  • Content Count

    35
  • Joined

  • Last visited

  • Days Won

    2

CptMercury last won the day on March 26 2018

CptMercury had the most liked content!

About CptMercury

  • Rank
    Junior Member

Recent Profile Visitors

255 profile views
  1. Can you insert your entire code? Then I could help you find the issue. If you kept the order of your function definitions, you need to change the order a bit, I will talk you through once posted the new code.
  2. So I did some small changes to your AE2Crafting.lua file, it should work now as intended. I wasn't able to test it yet, so tell me if it works or not. -- Original by Palagius : https://oc.cil.li/index.php?/topic/1426-ae2-level-auto-crafting/ -- Modfied by Dalden 2018-07-28 -- - Store crafting result object to check for status -- - If crafting job is not yet finished from previous cycle then skip this cycle local arg = {...} if not arg[1] then arg[1] = "009" else arg[1] = tostring(arg[1]) end if not arg[2] then arg[2] = "ac7" else arg[2] = tostring(arg[2]) end local component = require("component") local term = require("term") --local thread = require("thread") local event = require("event") local meController = component.proxy(component.me_controller.address) local gpu2p = component.proxy(component.get(arg[1])) local screen2 = component.get(arg[2]) local count = 0 startScreen(arg[1],arg[2]) gpu2p.setForeground(0xFFFFFF) --term.setViewport(nil, nil, nil, nil, nil, nil, window) -- Each element of the array is "item", "damage", "number wanted", "max craft size" -- Damage value should be zero for base items items = { { "minecraft:coal", 1, 100, 300 } -- { "minecraft:coal_block", 0, 10, 256 } -- { "minecraft:iron_ingot", 0, 16384, 256 }, -- { "minecraft:gold_ingot", 0, 16384, 256 }, -- { "minecraft:glass", 0, 16384, 256 }, -- { "minecraft:quartz", 0, 16384, 256 }, -- { "minecraft:diamond", 0, 16384, 256 }, -- { "minecraft:emerald", 0, 16384, 256 }, -- { "draconicevolution:draconium_ingot", 0, 16384, 256 }, -- { "thermalfoundation:material", 128, 1024, 256 }, -- Copper Ingot -- { "thermalfoundation:material", 129, 1024, 256 }, -- Tin Ingot -- { "thermalfoundation:material", 130, 1024, 256 }, -- Silver Ingot -- { "thermalfoundation:material", 131, 1024, 256 }, -- Lead Ingot -- { "thermalfoundation:material", 161, 1024, 256 }, -- Electrum Ingot -- { "thermalfoundation:material", 162, 1024, 256 }, -- Invar Ingot -- { "thermalfoundation:material", 163, 1024, 256 }, -- Bronze Ingot -- { "thermalfoundation:material", 164, 1024, 256 }, -- Constantan Ingot -- { "thermalfoundation:material", 165, 1024, 256 }, -- Signalum Ingot -- { "thermalfoundation:material", 166, 1024, 256 }, -- Lumium Ingot -- { "thermalfoundation:material", 167, 1024, 256 }, -- Enderium Ingot -- { "appliedenergistics2:material", 24, 4096, 256 }, -- Engineering Processor -- { "appliedenergistics2:material", 23, 4096, 256 }, -- Calculation Processor -- { "appliedenergistics2:material", 22, 4096, 256 }, -- Logic Processor -- { "appliedenergistics2:material", 11, 4096, 256 }, -- Pure Nether Quartz Crystal -- { "appliedenergistics2:material", 10, 4096, 256 }, -- Pure Certus Quartz Crystal -- { "appliedenergistics2:material", 7, 4096, 256 }, -- Fluix Crystal -- { "appliedenergistics2:material", 12, 4096, 256 }, -- Pure Fluix Crystal -- { "appliedenergistics2:material", 0, 4096, 256 }, -- Certus Quartz Crystal -- { "appliedenergistics2:material", 1, 4096, 256 }, -- Charged Certus Quartz Crystal -- { "appliedenergistics2:material", 8, 4096, 256 }, -- Fluix Dust -- { "appliedenergistics2:material", 2, 4096, 256 }, -- Certus Quartz Dust -- { "actuallyadditions:item_dust", 5, 4096, 256 }, -- Crushed Quartz -- { "enderio:item_material", 5, 4096, 256 }, -- Silicon -- { "enderio:item_alloy_ingot", 1, 1024, 256 }, -- Energetic Alloy Ingot -- { "enderio:item_alloy_ingot", 2, 1024, 256 }, -- Vibrant Alloy Ingot -- { "enderio:item_alloy_ingot", 5, 1024, 256 }, -- Pulsating Iron Ingot -- { "enderio:item_alloy_ingot", 6, 1024, 256 }, -- Dark Steel Ingot -- { "enderio:item_alloy_ingot", 7, 1024, 256 }, -- Soularium Ingot -- { "enderio:item_alloy_ingot", 8, 1024, 256 }, -- End Steel Ingot -- { "enderio:item_alloy_ingot", 0, 1024, 256 } -- Electrical Steel Ingot } loopDelay = 60 -- Seconds between runs -- Init list with crafting status for curIdx = 1, #items do items[curIdx][5] = false -- Crafting status set to false items[curIdx][6] = nil -- Crafting object null end local function loop() for curIdx = 1, #items do curName = items[curIdx][1] curDamage = items[curIdx][2] curMinValue = items[curIdx][3] curMaxRequest = items[curIdx][4] curCrafting = items[curIdx][5] curCraftStatus = items[curIdx][6] -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n") storedItem = meController.getItemsInNetwork({ name = curName, damage = curDamage }) drawText("Network contains ",gpu2p) gpu2p.setForeground(0xCC24C0) -- Purple-ish drawText(storedItem[1].size,gpu2p) gpu2p.setForeground(0xFFFFFF) -- White drawText(" items with label ",gpu2p) gpu2p.setForeground(0x00FF00) -- Green drawText(storedItem[1].label .. "\n",gpu2p) gpu2p.setForeground(0xFFFFFF) -- White if storedItem[1].size < curMinValue then delta = curMinValue - storedItem[1].size craftAmount = delta if delta > curMaxRequest then craftAmount = curMaxRequest end drawText(" Need to craft ",gpu2p) gpu2p.setForeground(0xFF0000) -- Red drawText(delta,gpu2p) gpu2p.setForeground(0xFFFFFF) -- White drawText(", requesting ",gpu2p) gpu2p.setForeground(0xCC24C0) -- Purple-ish drawText(craftAmount .. "... ",gpu2p) gpu2p.setForeground(0xFFFFFF) -- White craftables = meController.getCraftables({ name = curName, damage = curDamage }) if craftables.n >= 1 then cItem = craftables[1] if curCrafting then if curCraftStatus.isCanceled() or curCraftStatus.isDone() then drawText("Previous Craft completed\n",gpu2p) items[curIdx][5] = false curCrafting = false end end if curCrafting then drawText("Previous Craft busy\n",gpu2p) end if not curCrafting then retval = cItem.request(craftAmount) items[curIdx][5] = true items[curIdx][6] = retval gpu2p.setForeground(0x00FF00) -- Green drawText("Requested - ",gpu2p) --while (not retval.isCanceled()) and (not retval.isDone()) do -- os.sleep(1) -- io.write(".") -- end gpu2p.setForeground(0xFFFFFF) -- White drawText("Done \n",gpu2p) end else gpu2p.setForeground(0xFF0000) -- Red drawText(" Unable to locate craftable for " .. storedItem[1].name .. "\n",gpu2p) gpu2p.setForeground(0xFFFFFF) -- White end end end drawText("Sleeping for " .. loopDelay .. " seconds...\n\n",gpu2p) end event.timer(loopDelay, loop, math.huge) So what I did was removing your while loop, and just put the entire code inside that loop into a function called "loop". Then I set a timer with event.timer, that will wait "loopDelay" seconds until it calls the loop function. Since I added math.huge as third variable, the loop function will be called repeatedly.
  3. Well, I haven't done something similar yet, so I don't know if there's a way to have a program with and while loop running in the background, I did some quick test with coroutines, but it didn't seem to work. What would work is to use an event driven program, but that would require you to do some rewriting of your code. So what you would do is registering some events with event.listen(event_type, callback) and then having the corresponding callback do your stuff. For periodically stuff like checking your me system for items or whatever, you can register timers that are repeated infinitely with event.timer(interval, callback, math.huge), doing stuff that need to be triggered by time and not some user input or incoming modem messages or sth like that. That way, open os would run with the me programming running simultaneously.
  4. Hey, I didn't check the entire code, it's a lot of stuff to go through, but I found the reason for your error. You are calling string.gsub on a number, but it's a string lib, so you have to convert the number to a string first, by calling tostring(number). Your while loop in lines 219-224 would then look like this: while true do formatted, k = string.gsub(tostring(formatted), "^(%d+)(%d%d%d)", '%1,%2') if k == 0 then break end end May I also suggest to use local whenever possible? Like all variables, functions etc. It helps to reduce errors in form of variable overrides etc, plus access to locals is faster. Try that and see, if it works, if not, just post the error message and I'll have a look again.
  5. Yeah, @Molinko‘s code should work, response (in your code it’s „data“) is an iterator suited for „for .. in“ loops. You don‘t actally have to pcall it, calling web.request works also fine.
  6. Oh sorry, my bad, it's supposed to be tostring(str)
  7. It would be helpful to see the entire code of drawText, not only lines 39 - 50, but I may have found your problem. It seem like you named your variable 'string', is that right? If so, you are either overriding the global string variable, if you declared 'string' as a public variable, or if you used local, your code is not actually looking for the global 'string' variable, but for your local one. So basically, either way you don't have access to the string functions. In oder to solve this, you should not name your variables after globally ones unless you don't need to have access to them. Ok, for your code, you want a program that does a gpu set using a string or a number as input? And if it is a string, you want to replace all \n with ""? Then this might help: local function set(str, gpuProxy) checkArg(1, str, "number", "string") checkArg(2, gpuProxy, "table") -- checkArg to ensure you don't have any false input -- but you don't really need it if type(str) == "number" then str = tostring(str) elseif type(str) == "string" then str = str:gsub("\n", "") end gpuProxy.set(x, y, str) end
  8. The inputs for gpu.copy() are x, y, width, height, x_offset (relative position to x; so the new rectangle starts at coordinate x - tx), y_offset (same as for x_offset). So basically if you want to copy the lower part to the upper part, you have to call: gpu.copy(1, y/2, x, y, 0, -y/2) -- x_offset is 0 because you want to have the rectangle at the same x position as the old one -- y_offset is -y/2 (-25 for tier 3 screen), because the rectangle starts at a smaller y value compared to the old one
  9. 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.
  10. 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.
  11. Hey, here is a list of all methods for ic2 reactors. local component = require'component' local reactor = component.reactor reactor.getHeat() reactor.getMaxHeat() reactor.getReactorEUOutput() reactor.getReactorEnergyOutput() reactor.producesEnergy() You have to connect the reactor via an adapter.
  12. 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.
  13. 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.
  14. Ok, then it might be a bug, but I can't think of a reason why. Are you working with a computer or a robot? Could you send a screen shot of your setup? We might find a solution.
×
×
  • Create New...

Important Information

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