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

CptMercury

Members
  • Content Count

    43
  • 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

364 profile views
  1. I‘m not 100% sure, what causes the error, but it seems the installer doesn‘t handle the http request user data properly. You could try running the following command: wget https://raw.githubusercontent.com/zenith391/Fuchas/master/Installers/openos.lua installer installer Sadly I can‘t test this right now, but it might be worth trying. Edit: Ok, i figured out what is causing the error. The colon (:) in function call "data = con:read(math.huge)" in line 11 must be replaced with a period (.). So what definitely works is running pastebin get s2YZJ0T6 installer.lua replacing ":" with "." in line 11, and then run the installer. But I get an unrecoverable error on restarting the computer after successful installation...
  2. You can also use event timers. Then you need a function to check and send your stuff. local event = require "event" local function dostuff() -- this is ur function that is doing stuff end local interval = 20 -- time in seconds between the runs of the function event.timer(interval, dostuff, math.huge) -- math.huge for infinite repeats Or if you want to keep Skript as it is, you can use Molinko's approach with os.execute Then your code would be: event.timer(interval, function() os.execute("/path"), math.huge)
  3. Ok, I forgot the program doesn‘t always run in the executor thread. Too bad there are only ways to have blocking high precision sleeps and timers and no non-blocking alternatives... But anyways, thanks alot
  4. @payonel Hey, I was wondering if there is any chance to see a high precision computer.pull function in OpenComputers, allowing to have timeouts below one tick (I believe the currently used computer.uptime only returns time with .05 s precision). With that in hand, non-blocking sleeps and timers for small time intervals should be realizable. I was trying to implement this in openOS by adding a computer.pull function using os.clock instead of computer.uptime and changing some other libs accordingly, but it didn't work out. So I'm asking if there is any reason against adding a higher precision version of computer.pull to "machine"? Thanks:)
  5. Hey, you are correct, string metatables are protected, so you can‘t change or add functions. I assume, unicode.len(string) is not what you want, or is it? In case you want to have an object, you could interact with, you could build one. local unicode = require"unicode" local ucode = {} local mt = { __len = function(self) return unicode.len(self.string) end } function ucode.new(str) local obj = { string = str } return setmetatable(obj, mt) end return ucode Sorry for the code being just plane text, I’m on my mobile and dont know how to insert some code properly so i‘ll will make a proper one as soon as i get to my pc. You then add all the missing functions of the unicode or string lib that you want to the metatable, and then you are good to go. Btw, with the __len function, you should be able to call #objname, and it should return the correct length.
  6. Ok, I see. With the colors, I would use your custom table, it should be fine, so you don't need to require colors. Sadly I am really busy right now, so I can't have a look at the code for like 2 days. It would be great if you could try to do as many tests and improvements as possible, and then I will have a look at your new results.
  7. I‘m glad that I could help. You‘re welcome! Could you post the error message?
  8. Ok, so the issue with locals you had is the following. When using local, it's important to have the right order of variable/function definitions, let me give an example: local function func_x() print("X") end -- that is some random function local function func_xy() func_x() func_y() end -- a function that will call func_x amd func_y -- this will throw an error, because func_y is defined after it is called by func_xy local function func_y() print("Y") end -- you have to ensure the right order! Ok, so I did some rearrangement of your functions, I hope it works. local API = require("buttonAPI") -- On appelle l'API "buttonAPI" local component = require("component") -- On appelle l'API "component" local term = require("term") -- On appelle l'API "term" local event = require("event") -- On appelle l'API "event" local colors = require("colors") -- On appelle l'API "colors" -- you are overwriting the colors api later, do you actually need that api? local mon = component.gpu local trm = term local egy = component.energy_device local brR = component.br_reactor local brT = component.br_turbine local steamReactor = brR.isActivelyCooled() local menuType = "Reactor" local numCapacitors = 36 local turnOnAt = 50 local turnOffAt = 90 local targetSpeed = 1840 local energy = 0 local energyStored = 0 local energyMax = 0 local energyStoredPercent = 0 local timerCode local mode = "Automatic" local RFProduction = 0 local fuelUse = 0 local coreTemp = 0 local reactorOnline = false local rodLevel = 0 local turbineOnline = false local turbineRotorSpeed = 0 local turbineRFGen = 0 local turbineFluidRate = 0 local turbineInductor = false local OptFuelRodLevel = 0 -- COLORS -- here are you overwriting colors. If you only need this table, you can remove 'require("colors")' above. local colors = {} colors.white = 0xFFFFFF colors.orange = 0xFFA500 colors.magenta = 0xFF00FF colors.lightblue = 0x00AEEF colors.yellow = 0xFFFF00 colors.lime = 0x00FF00 colors.pink = 0xFFC0CB colors.gray = 0x555555 colors.lightGray = 0xD3D3D3 colors.grey = 0x555555 colors.silver = 0xAAAAAA colors.cyan = 0x00FFFF colors.purple = 0x800080 colors.blue = 0x0000FF colors.brown = 0x603913 colors.green = 0x008000 colors.red = 0xFF0000 colors.black = 0x000000 local function checkMode() API.toggleButton(mode) end local function menuMode() if steamReactor then if menuType == "Reactor" then API.setButton("Reactor", true) API.setButton("Turbine", false) else API.setButton("Reactor", false) API.setButton("Turbine", true) end end end local function online() brR.setActive(true) --API.flash("Online") end local function offline() brR.setActive(false) --API.flash("Offline") end local function setTurbineOnline() brT.setActive(true) --API.flash("Online") end local function setTurbineOffline() brT.setActive(false) --API.flash("Offline") end local function reactorOnOff() API.setButton("Online", brR.getActive()) API.setButton("Offline", not brR.getActive()) end local function turbineOnOff() API.setButton("Online", brT.getActive()) API.setButton("Offline", not brT.getActive()) end local function coilsOnOff() API.setButton("Coils On", brT.getInductorEngaged()) API.setButton("Coils Off", not brT.getInductorEngaged()) end local function coilsOn() brT.setInductorEngaged(true) end local function coilsOff() brT.setInductorEngaged(false) end local function fuelRodLevel() rodLevel = brR.getControlRodLevel(0) --print(rodLevel) trm.setCursor(30,5) trm.write(tostring(rodLevel).."%") mon.setBackground(colors.white) trm.setCursor(28,6) trm.write(" ") for i = 1,10 do trm.setCursor(28,i+6) mon.setBackground(colors.white) trm.write(" ") mon.setBackground(colors.yellow) trm.write(" ") if rodLevel/10 >= i then mon.setBackground(colors.red) else mon.setBackground(colors.yellow) end trm.write(" ") mon.setBackground(colors.yellow) trm.write(" ") mon.setBackground(colors.white) trm.write(" ") end trm.setCursor(28,17) trm.write(" ") mon.setBackground(colors.black) end local function turbineInductorDisplay() turbineInductor = brT.getInductorEngaged() trm.setCursor(30,5) if turbineInductor then trm.write("On") else trm.write("Off") end mon.setBackground(colors.gray) trm.setCursor(28,6) trm.write(" ") for i = 1,7 do trm.setCursor(28,i+6) mon.setBackground(colors.gray) trm.write(" ") mon.setBackground(colors.lightGray) trm.write(" ") if i % 2 == 0 then mon.setBackground(colors.gray) end trm.write(" ") mon.setBackground(colors.gray) trm.write(" ") if i % 2 ~= 0 then mon.setBackground(colors.lightGray) end trm.write(" ") mon.setBackground(colors.lightGray) trm.write(" ") mon.setBackground(colors.gray) trm.write(" ") end for i = 8,10 do trm.setCursor(28,i+6) mon.setBackground(colors.gray) trm.write(" ") mon.setBackground(colors.lightGray) trm.write(" ") if turbineInductor then mon.setBackground(colors.red) else mon.setBackground(colors.blue) end trm.write(" ") mon.setBackground(colors.gray) trm.write(" ") if turbineInductor then mon.setBackground(colors.red) else mon.setBackground(colors.blue) end trm.write(" ") mon.setBackground(colors.lightGray) trm.write(" ") mon.setBackground(colors.gray) trm.write(" ") end trm.setCursor(28,17) trm.write(" ") mon.setBackground(colors.black) end local function getClick() local event, side, x, y = event.pull(1,"touch") -- This should be the string "touch" as you want to look for a touch event, right? if x == nil or y == nil then local h, w = mon.getResolution() mon.set(h, w, ".") mon.set(h, w, " ") else API.checkxy(x,y) end end local function comma_value(amount) local formatted = amount local swap = false if formatted < 0 then formatted = formatted*-1 swap = true end while true do formatted, k = string.gsub(tostring(formatted), "^(%d+)(%d%d%d)", '%1,%2') if k == 0 then break end end if swap then formatted = "-"..formatted end return formatted end local function displayEn() trm.clear() trm.setCursor(1,1) --print("Energy Use: "..energy) trm.write("Energy Use: ") if energy < 0 then mon.setForeground(colors.red) else mon.setForeground(colors.green) end trm.write(comma_value(math.floor(energy)).. "RF/t") mon.setForeground(colors.white) trm.setCursor(1,2) trm.write("Energy Stored: "..energyStoredPercent.."%") if menuType == "Reactor" then trm.setCursor(1,3) trm.write("Reactor is: ") if reactorOnline then mon.setForeground(colors.green) trm.write("Online") else mon.setForeground(colors.red) trm.write("Offline") end mon.setForeground(colors.white) trm.setCursor(22,1) if steamReactor then trm.write("Steam: ") mon.setForeground(colors.green) trm.write(comma_value(math.floor(RFProduction)).."MB/t") else trm.write("RF Gen: ") mon.setForeground(colors.green) trm.write(comma_value(math.floor(RFProduction)).."RF/t") end mon.setForeground(colors.white) trm.setCursor(22,2) trm.write("Core Temp: "..math.floor(coreTemp).."c") trm.setCursor(22,3) trm.write("Fuel Use: "..fuelUse.."MB/t") else trm.setCursor(1,3) trm.write("Turbine is: ") if turbineOnline then mon.setForeground(colors.green) trm.write("Online") else mon.setForeground(colors.red) trm.write("Offline") end trm.setCursor(1,4) mon.setForeground(colors.white) trm.write("Reactor is: ") if reactorOnline then mon.setForeground(colors.green) trm.write("Online") else mon.setForeground(colors.red) trm.write("Offline") end mon.setForeground(colors.white) trm.setCursor(22,1) trm.write("RFGen: ") mon.setForeground(colors.green) trm.write(comma_value(math.floor(turbineRFGen)).."RF/t") mon.setForeground(colors.white) trm.setCursor(22,2) trm.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM") trm.setCursor(22,3) trm.write("Steam: "..comma_value(turbineFluidRate).."MB/t") end end local function checkEn() local tempEnergy = 0 energyStored = egy.getEnergyStored() energyMax = egy.getMaxEnergyStored() energyStoredPercent = math.floor((energyStored/energyMax)*100) RFProduction = brR.getEnergyProducedLastTick() fuelUse = brR.getFuelConsumedLastTick() fuelUse = math.floor(fuelUse*100) fuelUse = fuelUse/100 coreTemp = brR.getFuelTemperature() reactorOnline = brR.getActive() tempEnergy = egy.getEnergyStored() os.sleep(0.1) energy = (egy.getEnergyStored()-tempEnergy)/2 energy = energy*numCapacitors if steamReactor then turbineOnline = brT.getActive() turbineRotorSpeed = brT.getRotorSpeed() turbineRFGen = brT.getEnergyProducedLastTick() turbineFluidRate = brT.getFluidFlowRate() end end local function findOptFuelRods() trm.clear() brR.setActive(false) checkEn() displayEn() fuelRodLevel() while brR.getFuelTemperature() > 99 do for i= 1,3 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Finding Optimal Rod Level") trm.setCursor(3,7) trm.write("Core Temp: "..brR.getFuelTemperature()) trm.setCursor(3,8) trm.write("Waiting for 99c") os.sleep(1) end end while brR.getHotFluidAmount() > 10000 do for i = 1,3 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Finding Optimal Rod Level, please wait ....") trm.setCursor(3,7) trm.write("Fluid Amount: "..comma_value(brR.getHotFluidAmount()).."mb") trm.setCursor(3,8) trm.write("Waiting for 10,000mb") os.sleep(1) end end brR.setAllControlRodLevels(99) brR.setActive(true) while brR.getFuelTemperature() < 100 do for i = 1,5 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Set all rod levels to 99") trm.setCursor(3,7) trm.write("Waiting 5 seconds...") os.sleep(1) end end for i = 1,5 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Set all rod levels to 99") trm.setCursor(3,7) trm.write("Waiting 5 seconds...") os.sleep(1) end local tempMB = brR.getEnergyProducedLastTick() print(tempMB.."MB/t of steam") local tempRodLevels = math.floor(2000/tempMB) print("2000/"..tempMB.." = "..tempRodLevels) tempRodLevels = 100-tempRodLevels+5 print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels)) brR.setAllControlRodLevels(math.floor(tempRodLevels)) print("Waiting 10 seconds to confirm...") for i = 1,10 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Estimated Level: "..tempRodLevels) trm.setCursor(3,7) trm.write("Waiting 10 seconds...") os.sleep(1) end tempMB = brR.getEnergyProducedLastTick() while tempMB > 2000 do tempRodLevels = tempRodLevels+1 brR.setAllControlRodLevels(math.floor(tempRodLevels)) print("Setting Rod Levels to: "..tempRodLevels) for i = 1,5 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Getting below 2000mb/t") trm.setCursor(3,7) trm.write("Currently at: "..tempMB) os.sleep(1) end tempMB = brR.getEnergyProducedLastTick() end while tempMB < 2000 do tempRodLevels = tempRodLevels -1 brR.setAllControlRodLevels(math.floor(tempRodLevels)) print("Setting Rod Levels to: "..tempRodLevels) for i = 1,5 do checkEn() displayEn() fuelRodLevel() trm.setCursor(3,6) trm.write("Getting Above 2000mb/t") trm.setCursor(3,7) trm.write("Currently at: "..tempMB) os.sleep(1) end tempMB = brR.getEnergyProducedLastTick() end OptFuelRodLevel = tempRodLevels end local function setRods(setLevel) print("Setting Rod Level: "..setLevel) API.flash(tostring(setLevel)) brR.setAllControlRodLevels(setLevel) fuelRodLevel() end local function rodPlus() API.flash("+") brR.setAllControlRodLevels(rodLevel+1) fuelRodLevel() end local function rodMinus() API.flash("-") brR.setAllControlRodLevels(rodLevel-1) fuelRodLevel() end local function autoReactor() if not steamReactor then brR.setAllControlRodLevels(0) if energyStoredPercent < turnOnAt then if not reactorOnline then online() end end if energyStoredPercent > turnOffAt then if reactorOnline then offline() end end else brR.setAllControlRodLevels(OptFuelRodLevel) if energyStoredPercent < turnOnAt then --online() setTurbineOnline() coilsOn() end if energyStoredPercent > turnOffAt then --if turbineRotorSpeed > 1800 then -- offline() --else -- online() --end setTurbineOnline() coilsOff() end if turbineRotorSpeed > targetSpeed then offline() else online() end end end local displayScreen -- some of your functions calle ach other, that makes it hard to find a correct order -- so I just define displayScreen, so the function can be defined later local manualMode local function autoMode() local mode = "Automatic" displayScreen() end local function reactorMenu() local menuType = "Reactor" displayScreen() end local function turbineMenu() local menuType = "Turbine" displayScreen() end local function manualMenu() API.clearTable() API.setTable("Automatic", autoMode, "", 3, 13, 6, 6) API.setTable("Manual", manualMode, "", 15, 25, 6, 6) API.setTable("Online", online, "", 3, 13, 8, 8) API.setTable("Offline", offline, "", 15, 25, 8, 8) API.setTable("0", setRods, 0, 11,14, 10, 10) API.setTable("10", setRods, 10, 5,8, 12, 12) API.setTable("20", setRods, 20, 11,14, 12, 12) API.setTable("30", setRods, 30, 17,20, 12, 12) API.setTable("40", setRods, 40, 5,8, 14, 14) API.setTable("50", setRods, 50, 11,14, 14, 14) API.setTable("60", setRods, 60, 17,20, 14, 14) API.setTable("70", setRods, 70, 5,8, 16, 16) API.setTable("80", setRods, 80, 11,14, 16, 16) API.setTable("90", setRods, 90, 17,20, 16, 16) API.setTable("+", rodPlus, "", 23, 25, 12, 12) API.setTable("-", rodMinus, "", 23, 25, 16, 16) if steamReactor then API.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19) API.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19) end API.screen() checkMode() reactorOnOff() menuMode() end function manualMode() local mode = "Manual" manualMenu() end local function autoMenu() API.clearTable() API.setTable("Automatic", autoMode, "", 3, 13, 6, 6) API.setTable("Manual", manualMode, "", 15, 25, 6, 6) if steamReactor then API.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19) API.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19) end API.screen() checkMode() menuMode() end local function turbineAutoMenu() API.clearTable() API.setTable("Automatic", autoMode, "", 3, 13, 6, 6) API.setTable("Manual", manualMode, "", 15, 25, 6, 6) API.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19) API.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19) API.screen() checkMode() menuMode() end local function turbineManualMenu() API.clearTable() API.setTable("Automatic", autoMode, "", 3, 13, 6, 6) API.setTable("Manual", manualMode, "", 15, 25, 6, 6) API.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19) API.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19) API.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8) API.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8) API.setTable("Coils On", coilsOn, "", 3, 13, 10, 10) API.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10) API.screen() checkMode() turbineOnOff() coilsOnOff() menuMode() end function displayScreen() -- repeat checkEn() displayEn() if menuType == "Reactor" then fuelRodLevel() if mode == "Automatic" then autoMenu() autoReactor() else manualMenu() end else turbineInductorDisplay() if mode == "Automatic" then turbineAutoMenu() autoReactor() else turbineManualMenu() end end getClick() end if steamReactor then findOptFuelRods() end while true do displayScreen() os.sleep(1) end
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. Oh sorry, my bad, it's supposed to be tostring(str)
  15. 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
×
×
  • Create New...

Important Information

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