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


  • Content count

  • Joined

  • Last visited

  • Days Won


CptMercury last won the day on March 26

CptMercury had the most liked content!

About CptMercury

  • Rank
    Junior Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. CptMercury

    Problem with adapter using inventory controller upgrade

    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.
  2. CptMercury

    Can't unse OPPM

    Hey, don't know why oppm isn't working, but you can simply run this command: wget https://raw.githubusercontent.com/OpenPrograms/Sangar-Programs/master/geo2holo.lua geo2holo.lua
  3. CptMercury

    How can I identify a block without mining it?

    I guess the geolyzer would be your best choice. I have not worked with them yet, but I guess you could do the following: You scan a large area using the geolyzer, so you don't use the 'analyze' method but the 'scan' method, that way you can scan large areas at once. This is going to take a while, it takes (I think) 0.05 s to scan one block. The max column height is 64 blocks (32 up and 32 down) but sadly I can't tell you what's the radius of the geolyzer. You don't get the kind of block at each position but the 'density' and ores have a high density. That way you scan the entire area and know exactly where ores are and you don't waste time and energy digging around (since you said you would like to scan adjacent blocks I guess your robot would strip mine?). Looking at Sangar's 'geo2holo' program might help understanding how the 'scan' method works. https://github.com/OpenPrograms/Sangar-Programs/blob/master/geo2holo.lua
  4. CptMercury

    Problem with adapter using inventory controller upgrade

    Hey! That is very strange, as this should work. Try this, if this doesn't work, something must be wrong. local component = require'component' for i = 0, 5 do print(component.inventory_controller.getStackInSlot(i, 1)) end
  5. CptMercury

    Multi screen/screen mirroring

    Hey! It is not that hard to run a program on multiple screens and being able to interact with all monitors. If you want to have the terminal on multiple screens you could modify the modules and then restart the computer, but there might be a better solution than this. One gpu can only be bound to one screen, so you could basically write a lib that will redirect any gpu call to a function that iterates through all screens, binding the gpu and call the function for every screen. Instead of doing this by hand for every function, we're going to use metatables (if you don't know about metatables, you should definitely check them out, they are a really powerful tool in Lua). Basically metatables allow you to change the way how objects behave in different situations, for example when exposed to an arithmetic or relational operator (this way you can tell Lua how to add 2 tables, check for equality etc; in regular Lua, you can also change the metatables of strings, but opencomputers removes that ability). The most powerful meta methods are __index and __newindex. They are triggered when you look up (or modify) an absent key. Instead of returning nil, if present, these meta methods are invoked. The __index meta method is what we're going to use for the implementation. We create a proxy table for the gpu, that will then return a function to iterate over all the screens. local component = require'component' local gpu = component.gpu -- # create table containing all screens local screens = component.list('screen') -- # instead of invoking 'component.list' every time we make a gpu call -- # we just update the list whenever a screen is added or removed local function updatescreens(event, addr, ctype) if ctype ~= 'screen' then return nil end if event == 'component_added' then screens[addr] = 'screen' else screens[addr] = nil end end -- # listening to component adding or removing events, invoking 'updatescreen' on event require'event'.listen('component_added', updatescreens) require'event'.listen('component_removed', updatescreens) -- # creating proxy table for gpu calls local vgpu = {} -- # making vgpu its own metatable setmetatable(vgpu, vgpu) -- # would not make sense to call 'bind' for every screen vgpu.bind = gpu.bind -- # '__index' function function vgpu.__index(self, key) -- # since some gpu methods return some data, we differentiate between 'setter' and 'getter' methods -- # most setter function have 'set' in their name, 'fill' and 'copy' are the exception local setter = { copy = true; fill = true} if key:find('set') or setter[key] then -- # function that will only call the methods, does not return anything (for setters) return function(...) for addr in pairs(screens) do self.bind(addr) gpu[key](...) end end else -- # function that will return data (for getters) -- # returns table with screen address as key and table or single object as value -- # {'addr 1' = value1, 'addr 2' = value2, ...} return function(...) local res = {} for addr in pairs(screens) do self.bind(addr) local r = {gpu[key](...)} res[addr] = #r == 1 and r[1] or r end return res end end end -- returns gpu proxy, so it can be used as a module return vgpu If you have a keyboard attached to all screens, you are able to interact with all of them using a basic event handler. If you have any further questions, feel free to ask:)
  6. CptMercury

    Undocumented "window" parameter in the term API wiki

    @Piorjade What also helps to speed up screen redrawing is to update your screen dynamically, so that you are only reprinting the areas that actually changed. Also if you are moving large areas on your screen, like scrolling or dragging, make sure to use the gpu.copy method.
  7. CptMercury

    Variable in a path

    You can use io.open(path):read() to read a specific line, but only indirectly. But it might be easier to use the iterator io.lines(path). -- # use io.read to get the whole file, it returns a string; then use string.gmatch/string.match to extract the specific line -- # Examples: -- # Ex1: get line 5 local path = "/somepath" local count = 1 local targetline = 5 local file = io.open(path):read("*all") for line in file:gmatch("[^\n]+") do if count == targetline then return line end count = count + 1 end -- # Ex2: find line starting with # local path = "/somepath" local indicator = "#" local file = io.open(path):read("*all") return file:match("["..indicator.."][^\n]+") -- # io.lines iterator, returns new line whenever it's called -- # Examples: -- # Ex1: get line 5 local path = "/somepath" local count = 1 local targetline = 5 for line in io.lines(path) do if count == targetline then return line end count = count + 1 end -- # Ex2: find line starting with # local path = "/somepath" local indicator = "#" for line in io.lines(path) do if line:sub(1, #indicator) == indicator the return line end end I only got quotation marks in the string returned by io.open():read() when I just ran io.open():read() in the Lua prompt; when I used print(io.open():read()) or io.write(io.open():read()) it printed the string without quotation marks in the output.
  8. CptMercury

    Variable in a path

    Hey If you want to insert a variable into a existing string, you can use the concat operator .. (2 dots). io.open("/WH/db/"..LOC, "w") -- # this will create a string that starts with /WH/db/ and ends with the string contained by LOC
  9. CptMercury

    systeminfo - well... showing system information...?

    Looking good, neat program! Some advice for dealing with strings: If you want to print some text on your screen and insert some numbers/other variables/returns of functions etc. into that text, instead of writing one part of the text, writing the number, and write the second part of the text you can just concatenate(connect) the different strings and the numbers using the concat operator .. (2 dots), then print it. In other words, combine all the different parts of the text first, and then write it to the screen. This will reduce the number of lines in your code and less screen operations are performed. io.write("string1") io.write("string2") -- # -> string1string2 -- # you get the same result with io.write("string1".."string2") -- # -> string1string2 -- # you can include numbers with io.write("string"..1.."string"..2) -- # -> string1string2 -- # you dont have to use the strings/numbers directly, variables containing strings and numbers work fine as well local s = "string" local num1 = 1 local num2 = 2 io.write(s..num1..s..num2) -- # -> string1string2 -- # one example of your code would be: line 55 - 59 term.write("Energy available/maximum: "..computer.energy().."/"..computer.maxEnergy().."\n") And one question: do you actually want the program to wait before printing a new set of information on the screen or do you just want to let your program yield in order to avoid "too long without yielding errors"?
  10. CptMercury

    How to get CPU tier from computer.getDeviceInfo()?

    I think there might be a better solution, but this is what I came up with: local info = computer.getDeviceInfo() local cputier for k in pairs(info) do if info[k].class == "processor" then cputier = tonumber((info[k].product):match("%d")) end end
  11. CptMercury

    Making the result of an HTTP request readable output

    The main problem here is that "==" is used to compare two values and it returns true or false: 4 == 4 -> true; 4 == 5 -> false The other thing is that the response is not a string, but an iterator that will return the next line whenever you call it. local internet = require'internet' local url = '...' local response = interent.request(url) if response then for line in response do io.write(line.."\n") end end -- # response is an iterator, each time it's called it returns the next line/chunk, this is then stored in the var "line" -- # then you can use the var and print/write it, store it in a table etc
  12. CptMercury

    Output of Energy storage

    Well, more practical might be not the best way to put it, but it'll reduce the amount of components you need to hook up to your computer, so reading the energy consumption of a few energy cells or of hundreds doesn't really make a difference. But you need a central place to set this system up and each energy connection cannot connect with others from this point on. It also might require some more coding than using that simple approach. Basically you have an array of 2 energy cells for each base. The robot will move back and forth placing down the adapter and applying the Redstone signal to toggle the input for a second. Then it will remove the adapter again and moves to the next position. The computer then can read the energy consumption of each energy cell. Of cause this system is kinda complicated and might take some time to be set up, but it would be easy to extend that system. Biggest downside is all the energy lines cannot be interconnected after that point. You would need to run individual power lines to each base or use some means of wireless power transportation. Even though being somewhat strange looking and not that resource efficient in terms of energy cells/ cabling required it's certainly the most "practical" way I can come up with to solve your issue.
  13. CptMercury

    Output of Energy storage

    Ok, so how is your town‘s energy supply set up? Do you have central power generation and then transfer the energy to each base? If that‘s the case I might have a different approach that would make the setup smaller and more practical.
  14. CptMercury

    Output of Energy storage

    Hey, I hope I interpreted your question correctly. You want to monitor how much energy your base actually consumes, the rf/t that leaves your energy storage device and not the relative difference between input and output, right? I did some testing and I came up with a solution that give you exactly that, the rf/t output of the storage device (used TE energy cell), now matter how much you input. This will stop the output of the cell for a limited amount of time tho (this is needed to do the calculation), so it's best to put a small energy storage device between the actual energy storage where you do the monitoring and your grid feeding your machines. Basically what I do is the following: 1. measure the relative energy difference in the device for a given period of time, divided by the amount of ticks waited --> the DIFFERENCE between input and output ( in rf/t) 2. disable the energy output of the device by applying a Redstone signal 3. measure the energy difference again and reenabling the output again (again divided by amount of ticks) --> the TOTAL input (in rf/t) 4. getting the difference between total input and relative change in rf --> the output (in rf/t) local component = require'component' local energyCell = component.energy_device local rs = component.redstone local side = 4 -- # side where your energy storage device is (relative to redstone i/o) local wait = .5 -- # time waiting between checking the energy level function getOutput() local init_rf = energyCell.getEnergyStored() -- # rf base level os.sleep(wait) local rel_rf = (energyCell.getEnergyStored() - init_rf) / (wait + .05) / 20 -- # rf difference rs.setOutput(side, 15) init_rf = energyCell.getEnergyStored() os.sleep(wait) local tot_rf_in = (energyCell.getEnergyStored() - init_rf) / (wait + .05) / 20 -- # total rf input rs.setOutput(side, 0) local tot_rf_out = tot_rf_in - rel_rf -- # total rf output return tot_rf_out end -- # apparently it takes one tick to read the rf level in the device, that's why I added .05 seconds -- # to the time waited in the rf/t calculations -- # the rf/t values are 100% correct, at least for TE energy cell you have to set the Redstone behavior to disable output when a Redstone signal is applied
  15. CptMercury

    Thermal expansion machines

    Ok, did some testing: You can see whats going on in a TE machine by using an adapter with an inventory controller inside, but you can not push items in/pull items out. For i/o interaction you have to use an robot equipped with an inventory controller. Then you can transfer items in and out of the machine using the robots inventory as a buffer. local component = require'component' local inv = component.inventory_controller local side = x -- #side where your inventory is attached -- #i/o stuff inv.suckFromSlot(side, slot, itemCount) inv.dropIntoSlot(side, slot, itemCount) -- #inventory checking inv.getStackInSlot(side, slot) inv.getInventorySize(side) Btw, the machine's side facing the robot/adapter must be set to the grey i/o configuration, in order to get access to all slots of the machine.

Important Information

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