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


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by CptMercury

  1. You're welcome. I'm glad I could help:) I was digging in the source code and it seems like a commit from January fixed that weird behavior. Some if-statement blocked incoming wireless messages while allowing wired messages to be accepted. In the newest version ( it should work as intended.
  2. There is some issue with the tier 1 card. I usually use tier 2 anyways, therefore I didn't notice. Tried with a tier 1 card and I was able to replicate your findings. So for now, I would simply use a tier 2 card in the robot and computer and everything will work just fine without a relay. I'll probably have a look in the tier 1 card's source code later and file a bug report on github (unless you want to do that)
  3. I downloaded a modpack with the same OC version ( and everything worked just fine without any relay. I ran --# receiver modem = require "component".modem modem.open(1) =event.pull("modem_message") --# sender modem = require "component".modem modem.open(1) modem.broadcast(1, "hi") (basically the same as yours) in the lua prompt on both the computer and the robot. There was no relay and the devices where over 10 blocks apart and sending the messages worked from robot to computer and computer to robot. I don't really have an idea what is going on with your setup. You could try to run =modem.getStrength() in the lua prompt at both machines. The default strength is 400, but there might be some custom config settings for your modpack. If the strength is too small, the signal doesn't reach the other machine, and placing them next to each other might cause them to be in range and transmit the message. If that's still doesn't resolve your issue, you could post a screenshot of the components in your robot and computer. You can add snippets to you post with and change the syntax highlighting to lua (lower right corner). Also, if you have code on a computer in Minecraft, you can either upload it to pastebin with pastebin put /path/to/file and then copy your code from pastebin.com (requires an internet card, you can temporarily insert one) or go into the saves folder of your Minecraft world, go to open computers folder and look inside the folder with the same name as the hard drive address of the computer you are using.
  4. Hey If done correctly, you don’t need the relay. Communication between multiple computers/drones etc works just fine without. The way your setup behaves is somewhat strange, I can try to replicate this later. Anyways, do you have a wireless network card in both the computer and the robot? (I assume by drone you mean the machine called EDI in your screenshot, right) Also, the code you showed looks somewhat fine I guess, but it would be helpful if you could post both as full program, preferably not as screenshot but as snippets.
  5. This is from the OC Wiki: Idk if they forgot to list microcontrollers or they left them away intentionally because they aren't supported. But since drones work I don't really see why microcontrollers shouldn't.
  6. What exactly do you need help with? The sending and executing commands? BTW, Payonel has created a great program called psh, that does exactly that. So you can have a look there, you might get some inspiration on how to tackle some of your problems.
  7. Let me try to explain what's happening here. First, create a file called t.lua: print(xyz) xyz = 12345 If you run the script once, it will print: nil Then, you run it again it and it will print: 12345 So, why is that? The answer is global variables. With the statement xyz = 12345 you declare a global variable, and these variables live longer than the script. In fact, in OC they live until the computer shuts down. In the entire script you posted does not define the following variables. FR1, FR2, FR3, FR4 FR1D, FR2D, FR3D, FR4D FR1MD, FR2MD, FR3MD, FR4MD FR1C, FR2C, FR3C, FR4C And since you did not declare those, your script looks them up in the global table. There Lua finds some of them, because some code you ran before declared them as global variables, and they still there. So, always define the variables that you use inside your script; and declare them as locals WHEREVER possible. Because when you leave the the script (or each enclosing block) the locals are deleted and don't pollute the global environment. This part here looks like you try to change or declare variables by putting them into a function. But that does not work. When you declare a variable like this: var1 = some_value -- or as local local var1 = some_value you push some_value into the variable. If you then take a function: local function test(a, b) -- do something end and call it like local var2 = some_other_value test(var1, var2) you DO NOT give that variable to the function so the function can modify that variable. Instead, the value that is stored in the variables are copied and passed to the function as arguments. That means, if you put a new value into the argument within the function, it is only changed inside that function, the outer variable will still contain the old value. Therefore, if you want to change some value using a function, there are two possibilities. -- #1 functions to perform a specific task -- in this case, changing a variable declared before local x = 5 -- x is 5 local function square() x = x^2 end -- x is still 5 -- calling the function now then changes the value square() -- x is now 25 --*********************************************************+-- -- #2 function to compute a value and return it local function square1(n) return n^2 end local y = square1(5) -- y is 25 For your use, the second method is more suitable. Here is an implementation of your function above. local function getDur(slot) local fuel_rod = ic.getStackInSlot(SIDE, slot ) local color -- you dont need to initialize it with a value local dmg = fuel_rod.damage local maxdmg = fuel_rod.maxDamage if dmg == 0 then color = "0x008421" elseif dmg > 0 and frdmg < 2500 then color = "0x00FF00" elseif dmg >= 2500 and frdmg < 5000 then color = "0xFFFF00" elseif dmg >= 5000 and frdmg < 7500 then color = "0xFFA800" elseif dmg >= 7500 and frdmg < 10000 then color = "0xFF6D00" elseif dmg >= 10000 and frdmg < 12500 then color = "0xFF3A00" elseif dmg >= 12500 and frdmg < 15000 then color = "0xFF2B00" elseif dmg >= 15000 and frdmg < 17500 then color = "0xFF0000" elseif dmg >= 17500 and frdmg < 20000 then color = "0x970000" end -- you only need to return what you really need return fuel_rod, slot, dmg, maxdmg, color end local FR1, slot1, FR1D, FR1MD, FR1C = getDur(21) local FR2, slot2, FR2D, FR2MD, FR2C = getDur(25) local FR3, slot3, FR3D, FR3MD, FR3C = getDur(30) local FR3, slot3, FR3D, FR3MD, FR3C = getDur(34) print(FR1D, FR1MD, FR1C) print(FR2D, FR2MD, FR2C) print(FR3D, FR3MD, FR3C) print(FR4D, FR4MD, FR4C) Hope that helps.
  8. Found the bug in the draw_fuel_rods function. Simply replace the old with: local function draw_fuel_rods(component_list) local fuel_rods = {} for _, item in ipairs(component_list) do if item.name == "Quad Fuel Rod (Uranium)" then local str = string.format( "%d:%s<color fg=0x%x>%d</color>/%d", #fuel_rods + 1, spacings[math.floor(math.log(item.damage, 10))], item.color, item.damage, item.max_damage ) table.insert(fuel_rods, str) end end fuel_rods = table.concat(fuel_rods, " | ") gp.setForeground(colors.green) centerF(6, string.format("Brennstäbe")) local len = #fuel_rods:gsub('<color.->(.-)</color>', function (a) return a end) term.setCursor((gp.getResolution() - len)/2, 7) gp.setForeground(colors.white) aw.write(fuel_rods) end Also, add term.clear() above the main loop
  9. Ok, so here you go. I made a some changes to increase performance and to make it easier to understand and extend, although if you really want to ha it adapt to some new situations, it needs a few minor tweaks. local component = require("component") local computer = require("computer") local term = require("term") local aw = require("adWrite") local gp = component.proxy(component.get("6fa6e9ed")) local rc = component.proxy(component.get("c3f546da")) local ic = component.proxy(component.get("2a60f6e0")) local tr = component.proxy(component.get("7621f0f8")) local rslamps = component.proxy(component.get("61d91131")) local rsreactor = component.proxy(component.get("a0a9b4d3")) -- CONFIG ---------------------------------------------------------------------- local SIDE = 3 local REACTOR_LAYOUT_WIDTH = 9 local REACTOR_LAYOUT_HEIGHT = 6 local REACTOR_LAYOUT_X = math.floor( (gp.getResolution() - REACTOR_LAYOUT_WIDTH + 0.5) / 2 ) local REACTOR_LAYOUT_Y = 10 -------------------------------------------------------------------------------- local colors = { green = 0x00FF00, yellow = 0xFFFF00, orange = 0xFFA800, black = 0x000000, white = 0xFFFFFF, red = 0xFF0000, blue = 0x0000FF, cyan = 0x00FFFF } local dmg_colors = {[0] = 0x008421, 0x00FF00, 0xFFFF00, 0xFFA800, 0xFF6D00, 0xFF3A00, 0xFF2B00, 0xFF2B00, 0xFF0000 } local function get_component_info(slot) local item = ic.getStackInSlot(SIDE, slot) local name = item.label local dmg = item.damage local max_dmg = item.maxDamage local percent = math.ceil(dmg / max_dmg * 8) local color = dmg_colors[percent] or 0x787878 return name, color, dmg, max_dmg end local function make_component_list() local res = {} for slot = 1, 54 do local name, color, dmg, max_dmg = get_component_info(slot) if name == "Quad Fuel Rod (Uranium)" then res[slot] = { name = name, color = color, damage = dmg, max_damage = max_dmg } else res[slot] = { name = name, color = color } end end return res end local component_symbol = { ["Overclocked Heat Vent"] = "X", ["Component Heat Exchanger"] = "W", ["Component Heat Vent"] = "O", ["Quad Fuel Rod (Uranium)"] = "U" } local function draw_reactor_layout(component_list) -- grouping the symbols with the same color local sorted_by_color = {} for i = 1, #component_list do local item = component_list[i] local color = item.color sorted_by_color[color] = sorted_by_color[color] or {} table.insert(sorted_by_color[color], {i, component_symbol[item.name]}) end -- draw the reactor layout for color, items in pairs(sorted_by_color) do for _, item in ipairs(items) do local slot = item[1] local x = (slot % REACTOR_LAYOUT_WIDTH) + REACTOR_LAYOUT_X - 1 local y = math.floor(slot / REACTOR_LAYOUT_WIDTH) + REACTOR_LAYOUT_Y if x == REACTOR_LAYOUT_X - 1 then x, y = REACTOR_LAYOUT_X + REACTOR_LAYOUT_WIDTH - 1, y - 1 end gp.setForeground(color) gp.set(x, y, item[2]) end end end local function centerF(row, str) w = gp.getResolution() term.setCursor((w - #str)/2, row) term.write(str) end local function draw_header() gp.setForeground(colors.orange) centerF(2, "---------------------------------------------------") centerF(3, "----- Atomreaktor -----") centerF(4, "---------------------------------------------------") end local spacings = {[0] = " ", " ", " ", " ", " ", [math.log(0, 10)] = " " } local function draw_fuel_rods(component_list) local fuel_rods = {} for _, item in ipairs(component_list) do if item.name == "quad fuel rod" then local str = string.format( #fuel_rods + 1, "%d:%s<color fg=%d>%d</color>/%d", math.floor(math.log(item.damage, 10)), item.color, item.damage, item.max_damage ) table.insert(fuel_rods, str) end end fuel_rods = table.concat(fuel_rods, " | ") w = gp.getResolution() term.setCursor((w - #fuel_rods)/2, 7) gp.setForeground(colors.white) aw.write(fuel_rods) end local function draw_legend() gp.setForeground(colors.yellow) centerF(17, "Legende") term.setCursor(1, 18) gp.setForeground(colors.white) term.setCursor(20, 18) aw.write("X = Übertakter Hitzeabzug") term.setCursor(20, 19) aw.write("O = Komponenten-Hitzeabzug") term.setCursor(20, 20) aw.write("U = Vierfach-Brennstab (Uran)") term.setCursor(20, 21) aw.write("W = Komponenten-Wärmetauscher") end -- this finished the drawing with status etc local function draw_rest() local rcHeat = rc.getHeat() local rcMaxHeat = rc.getMaxHeat() local rcProzent = math.ceil(rcHeat / rcMaxHeat * 4) local rcStatus = "" if rcProzent == 0 then rcStatus = "<color fg=0x00FF00>Alles OK </color>" -- rsreactor.setOutput(3, 20) elseif rcProzent == 1 then rcStatus = "<color fg=0xFFFF00>Warm</color>" elseif rcProzent == 2 then rcStatus = "<color fg=0xFFA800>Sehr Warm</color>" elseif rcProzent == 3 then rcStatus = "<color fg=0xFF3A00>Sehr Heiß</color>" elseif rcProzent == 4 then rcStatus = "<color fg=0xFF0000>ACHTUNG KERNSCHMELZE STEHT BEVOR!</color>" -- rsreactor.setOutput(3, 0) end term.setCursor(30, 23) aw.write("Reaktor Status: " ..rcStatus) local rcOnline = rc.producesEnergy() if rcOnline then term.setCursor(1, 24) gp.setForeground(colors.green) centerF(24, "Online") else term.setCursor(1, 24) gp.setForeground(colors.red) centerF(24, "Offline") end end while true do local component_list = make_component_list() gp.setBackground(0x000000) draw_header() draw_fuel_rods(component_list) draw_reactor_layout(component_list) draw_legend() draw_rest() os.sleep(1) end I wrapped the legend drawing part and the status drawing part in functions, but I din't change them. Also, the header drawing part wasn't altered much as well. I made changes to how the fuel rod damages and the reactor layout are rendered. And I also changed the way how the different reactor components are analyzed and stored. It should work, I tested in Minecraft. If some parts of the code are unclear, just let me know and I try my best in explaining what I did and why.
  10. That is a really weird bug. I don't really have an idea where exactly this is coming from, especially what function tries to yield. What version of OC are you running? I couldn't find the lines in my machine.lua file that your traceback is showing. But besides that, using the adwrite function for this is not really appropriate. I have written this function for really basic string coloring, it was not optimized for printing text where every character has a different color. I'll post a more suitable method for this in a few minutes.
  11. Ok, and then the characters should have the color of their damage value?
  12. Ok, I missed an opening "<" in line 137 apparently. Change the string to "1: <color fg=%d>%d</color>/%d | 2: <color fg=%d>%d</color>/%d | 3: <color fg=%d>%d</color>/%d" And btw, I saw you were collecting the information about all your components in the reactor but only printing the data of your fuel rods. Do you plan on displaying all the data or just for the fuel rods?
  13. Yea, I accidentally added a pair of extra curly braces in line 104. Change it to: local BS_slots = { 21, 25, 30, 34 } Ahh, ok, now I understand. I'll have a look at the file.
  14. CptMercury


    Just add this to your code: local shell = require "shell" local args, ops = shell.parse(...) You can read more on the shell.parse function here. But basically, options following a single '-' is split into single characters (that means -test sets the options t, e, s, t and NOT a single option called "test). To have an option name with more characters, use the double '--' following the name (--test will set a single option called "test") So, if you have a file test.lua, you could add the following (of cause also adding the 2 lines above as well) if args.o then -- do some stuff end if args.p then -- do something else end if help then -- print some help message end and then call it like: ' test.lua -op --help'.
  15. Alright. What does getFuel() return?
  16. Well, you have the function getFuel, which according to the site you've linked should return the amount of Deuterium and Tritium fuel, but I can't tell you in which form. It says something about D-T-fuel which comes from mixing both in a chemical infuser, but I haven't used mechanism in a while so can't help you out there. Also, have you tried calling getDeuterium() or getTritium()?
  17. I'm glad I could help
  18. I'm sorry I couldn't get back to you sooner, but I saw @Nexarius was helping you out. As Nexarius has pointed out, your function doesn't declare these variables. I sadly can't open the files you posted, it seems as they are no longer available, but I took the file Nexarius posted as a starting point. There I still see variables that are not declared (BS1C, BS1D, BS1MD, BS2C, BS2D, BS2MD, BS3C, BS3D, BS3MD) I assume these stand for color (BS1C), damage (BS1D) and max damage (BS1MD), am I correct? But what is the BS1S etc for? From the script it looks like it is the damage swell, but I'm not sure. If you could tell more details about what your code does, I can help you to make it even better, I already have some good ideas. (If you want to share code again, please add the code to the reply like Nexarius and I are doing) Anyways, I already took the code and modified it to some extend, always commenting what changes I made and why. (In terms of the undeclared variables, I used the values for color, damage and max damage and removed the first values BS1S, BS2S and BS3S since I couldn't figure out, what they should represent, and I also didn't do the padding, but it's no big deal to add that later) local component = require("component") local computer = require("computer") local term = require("term") local aw = require("adWrite") -- component.<component name> is equal to component.getPrimary(<component name>) -- just looks a bit clearer -- might be a good way to handle the following 3 components aswell local ic = component.inventory_controller local gp = component.proxy(component.get("6fa6e9ed")) local rc = component.proxy(component.get("c3f546da")) local tr = component.proxy(component.get("7621f0f8")) local rslamps = component.proxy(component.get("61d91131")) local rsreactor = component.proxy(component.get("a0a9b4d3")) local colors = { green = 0x00FF00, yellow = 0xFFFF00, orange = 0xFFA800, black = 0x000000, white = 0xFFFFFF, red = 0xFF0000, blue = 0x0000FF, cyan = 0x00FFFF } -- aw.write takes only one parameter, so using varargs doens't help you -- also, that way your intention is clearer function write(zeile, spalte, str) term.setCursor(spalte, zeile) aw.write(str) end -- here, you don't even have more that 2 arguments, so leave the vararg part function centerF(row, str) -- you only need the width, so don't bother getting the height w = gp.getResolution() -- using the # operator is faster than using string.len term.setCursor((w - #str)/2, row) -- first, don't use string.format here because you are not formatting anything -- so that would be a waste of time -- second, I would use term.write or io.write instead of print -- but print adds a newline following the string, so if you really want that, -- add a newline: term.write(str, "\n") term.write(str) end gp.setResolution(67, 24) term.clear() term.setCursor(1 ,1) -- colors are numbers now, not strings, but if you really want them to be -- strings, thats possible aswell local dmg_colors = {[0] = 0x008421, 0x00FF00, 0xFFFF00, 0xFFA800, 0xFF6D00, 0xFF3A00, 0xFF2B00, 0xFF2B00, 0xFF0000 } -- This is a faster and slightly more readable function than the original one. -- instead of using long elseif using a look-up table is often the better option -- here I am scaling the damage to a number between 0-8, using math.ceil -- and then using the number to get the correct color from the table -- the last color you had in the final else statement would have never been -- reached, therefore i left it local function getDuri(slot) local item = ic.getStackInSlot(3, slot) local dmg = item.damage local maxdmg = item.maxDamage local prozent = math.ceil(dmg / maxdmg * 8) local dmgColor = dmg_colors[prozent] return {item, dmg, maxdmg, dmgColor} end -- this will do the same as your previous function; string.rep(str, n) will -- return an empty string when n is < 1 local function makepadding(text, max) return string.rep(" ", #tostring(text) - max) end -- I moved the tables form the pairs function outside of the loop to prevent -- creation of 3 new tables each time; this is more efficient local UH_slots = { 1, 2, 4, 5, 6, 8, 9, 12, 16, 19, 20, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 35, 36, 39, 43, 46, 47, 49, 50, 51, 53, 54 } local KW_slots = { 10, 11, 13, 14, 15, 17, 18, 37, 38, 40, 41, 42, 44, 45 } local BS_slots = { {21, 25, 30, 34} } while true do gp.setBackground(colors.black) local UH = {} for i, slot in ipairs(UH_slots) do UH[i] = getDuri(slot) end local KW = {} for i, slot in ipairs(KW_slots) do KW[i] = getDuri(slot) end local BS = {} for i, slot in ipairs(BS_slots) do BS[i] = getDuri(slot) end local line = string.rep("-", 51) gp.setForeground(colors.orange) centerF(2, line) centerF(3, "----- Atomreaktor -----") centerF(4,line) gp.setForeground(colors.green) -- string.format doesn't do anything here, so simply pass the string centerF(6, "Brennstäbe") term.setCursor(2, 7) -- This time we actually use string.format local str = string.format( "1: <color fg=%d>%d/color>/%d | 2: <color fg=%d>%d</color>/%d | 3: <color fg=%d>%d</color>/%d", -- number in first square brackets is for the selecting the fuel rod -- the second numbers: 4 is color, 2 is damage, 3 is max damage BS[1][4], BS[1][2], BS[1][3], BS[2][4], BS[2][2], BS[2][3], BS[3][4], BS[3][2], BS[3][3] ) -- The numbers aren't padded (using makepadding), but you can easily add that aw.write(str) os.sleep(1) end
  19. This does not look like the actual script you are running, I don't see any variable (like FR1D, FR1MD) etc that is getting declared. Also, are you trying to pass some variable (FR1C for example) to the getDur function and expect it to set the value of this variable to the color? Because that does not work, since the parameters to a function are local, you could manipulate a global value, pass a table to the function and set a color attribute of the table or simply return some values. It would help if you could share the actual script, and then I am able to help you solve your problem.
  20. local debug = require "debug" local player = debug.getPlayer("<Name>") local x, y, z = player.getPosition()
  21. Thanks I'm glad I could help. Yes, you can add as many elseif statements with other slaves. But if you have a lot, then you might think about other solutions like using a table, as I mentioned above. This then has better readability and better performance. The string containing "%s" is a format string. The "%s" is a place holder and at that position a string is filled in. There are multiple types of placeholders, for example "%d" and "%f", which are placeholders for integers and floats. You can read more on that at http://www.lua.org/manual/5.3/manual.html#pdf-string.format and https://en.wikipedia.org/wiki/Printf_format_string. Yeah, this is totally possible since you distinguish the slaves by their addresses, so use only 1 port.
  22. Sure, you can do this in multiple ways. You can put the messages into a table, or if you have a given number of slaves, you can have separate variables for this. local event = require "event" local reactor1, reactor2 = "", "" -- # initialize both with an empty string while true do local _, _, addr, port, _, message = event.pull("modem_message") if addr == "address slave1" then reactor1 = message elseif addr == "address slave 2" then reactor2 = message end print(string.format("Reactor 1: %s\nReactor 2: %s", reactor1, reactor2)) end This will print the reactor status and will update in real time. Keep in mind that the first time it will print the text with only one message, since the second message hasn't been received yet. Also, you need to add the actual addresses of the modems in the if statement (replacing "address slave1/2" is)
  23. The inconsistency comes from you pulling events twice and storing them to separate variables. That can mess up the different senders in your network. So what you need to do is pull an event once, check the sender's address and then perform some tasks based on the addresses. local event = require "event" while true do local _, _, addr, port, _, message = event.pull("modem_message") if addr == "one address" then -- # do some stuff elseif addr == "the other address" then -- # do some other stuff -- # you can add as many addresses in elseif statements as you want end end Or you use a a table to map functions to addresses. local event = require "event" local addresses = { ["address1"] = function (msg) -- # do stuff end, ["address2"] = function (msg) -- # do other stuff end -- # you can add as many addresses and functions as you want } while true do local _, _, addr, port, _, message = event.pull("modem_message") if addresses[addr] then addresses[addr](message) end end
  24. Yeah, so the 'suckFromSlot'-method does not move items. I haven't found bugs in your code, so I assume it works. So here are a few questions: - Is the inventory of your robot full? - Were items sucked from the output slot in the loops before? Maybe you cannot extract items from that side of the machine? - What is the standard stack size of the output slot? try to read it when there are no items in this slot
  25. Hey, The issue seems to be related to the 'inventory.suckFromSlot' method, as you can see from your log 'Sucked items:false'. The 'false' indicates that the method was called, but failed. There are several reasons why this method could fail, but since it works in the beginning, parameters like the slot-number should be correct. So I guess either there is not enough inventory space in your robot or there is a calculation error within your 'getExternalSlotDetails' function. You could provide the code for your other utility functions, then I can have a look at them.
  • Create New...

Important Information

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