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

CptMercury

Members
  • Content Count

    54
  • Joined

  • Last visited

  • Days Won

    3

CptMercury last won the day on August 11

CptMercury had the most liked content!

1 Follower

About CptMercury

  • Rank
    Junior Member

Recent Profile Visitors

510 profile views
  1. You want a progress bar for the file transfer via modems? There is no built-in method available, so you need custom scripts for this. My approach would start with calculating the file's size and transmitting it to the receiving computer. Then the file is split into packets and transferred; by the size of the arriving packets the progress can easily be calculated. The remaining question is how to split the file. You could either send line by line or send a fixed number of bytes. Depending on your choice, the calculation method for the file size will vary. Number of lines: local n = 0 -- number of your lines for _ in io.lines("path/to/file") do n = n + 1 end Number of bytes: -- Method 1: local function filesize (file) local pos = file:seek() local size = file:seek("end") file:seek("set", pos) return size end -- open file and call function with file local f = assert(io.open("path/to/file")) local n = filesize(f) -- Method 2: local f = assert(io.open("path/to/file")) local data = f:read("*all") local size = #data The only thing you then need is a way to display the progress, either by simply printing the percentage or by drawing a more or less detailed progress bar. I hope in correctly interpreted your question and this gets you started. Feel free to ask if you need further assistance.
  2. Well, you can use “not“, which will do exactly what you‘re trying to do. if not (val > x and val < y) then -- do stuff end But: - not greater than is the same as less than (actually less or equal <=) - not less then is the same as greater than (greater or equal) It would look like this: if val <= x and val >= y then -- do stuff end
  3. Well, you actually just need a computer and an adapter to interact with me-components (not even an inventory_controller upgrade). You also require an database component to configure me I/o stuff (export busses, import busses and interfaces) In order to properly use the export bus, you need to have access to the items in the network. Then, using the database component, you can store information about a stack of items in the database and use this to configure the export bus. The functions for accessing the items in the network are provided by the "common network api", which should be shared by all me-components. BUT for some reason, this api can only be accessed by the me-controller (at least in the 1.12 I'm using atm). Which means, you need to directly place your adapter next to the me-controller. There might be a work-around, tho. Look for an item called MFU by open computers. If you have it in your version, shift-right-click with this item on the me controller and place it in an adapter. Then you should find the component me_controller. If this works for you, let me know and I'll help you with the database stuff to actually configure the export bus if you have trouble to do so.
  4. @Chaoschaot234 I think this version is deprecated. Dustpuppy made a new guy lib with more features etc. Have a look at it. Here's the forum post Its installer link is working properly, I just checked.
  5. Ok, as promised, here is a more advanced function. Instead of giving it one string and specify its color, you mark parts of the string and specify foreground (and also background) color by using a xml/html like syntax. If you want to change on part of the string, put it between <color fg=hex, bg=hex>your string goes here</color>. Hex is the color code starting with 0x (like 0xFFFFFF). You don't have to specify both, background and foreground, just set the color you like to change; if you set both, use a comma (,) as delimiter. local component = require "component" local term = require "term" ------------------------------------------------------------------------------- local gpu = component.gpu local adWrite = {} function adWrite.write(s) local cbg, cfg = gpu.getBackground(), gpu.getForeground() local i = 1 s:gsub('()<color(.-)>(.-)</color>()', function(i1, tag, content, i2) local bg, fg if not i1 then return end term.write(s:sub(i, i1-1)) tag = tag:gsub('%s', "") -- remove whites paces for colortype, color in tag:gmatch '([bfg][bfg])=(0[xX]%x+)' do if colortype == "bg" and color then bg = tonumber(color) elseif colortype == "fg" and color then fg = tonumber(color) end end if bg and bg ~= cbg then gpu.setBackground(bg) end if fg and fg ~= color then gpu.setForeground(fg) end term.write(content) gpu.setBackground(cbg) gpu.setForeground(cfg) i = i2 end) if i <= #s then term.write(s:sub(i, #s)) end end ------------------------------------------------------------------------------- return adWrite Here is an example:
  6. I assume you are currently using the term lib for writing stuff on the screen? For full control over the screen, you need to interact with the gnu component directly. You then need to also specify the x and y coordinate where your text starts. But it's easy to write a function that works exactly like term.write but allows you to specify the colors of each part of the string. local component = require "component" local term = require "term" local unicode = require "unicode" local gpu = component.gpu local function advancedWrite(s, c) -- s is the string, c is its color local x, y = term.getCursor() local max_x, max_y = gpu.getResolution local len = unicode.len(s) local old_fg = gpu.setForeground(c) gpu.set(x, y, s) gpu.setForeground(old_fg) if x + len >= max_x then x = 1 y = y + 1 else x = x + len end term.setCursor(x, y) if x + len >= max_x then return advancedWrite(unicode.sub(s, max_x-x), c) end end This is a really simple and inefficient approach. I haven't tested it yet but I will once I'm back at my computer. I will also post a proper function later, if that is the type of solution you're looking for.
  7. Well, first of all, if you only need the message to contain one string, then you are better off by just sending the string as the message, so no need to make a table with that string, serialize the table transforming it into a string which is then send via the modem, once received, transformed back into a table which is then indexed to get the string you want to send... But anyways, I would assume the error with the serialization comes from trying to serialize a nil value. You're using a timeout with your event.pull, that means, event.pull returns nil if no modem_message was received within that 239 seconds. So either you simply remove the number specifying the timeout, or you add an if-statement checking whether you actually received a message and skip the serialization part when the message is nil. -- without the timeout, if this is possible, but it looks like you want your robot to execute some stuff every 239 seconds function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, serialized_message = event.pull("modem_message") received_table = require("serialization").unserialize(serialized_message) if recieved_table.loopSwitch == "off" then loopOff = true end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end -------------------------------- -- with an if statement verifying there actually was a message received function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, serialized_message = event.pull(239, "modem_message") if serialized_message then received_table = require("serialization").unserialize(serialized_message) if recieved_table.loopSwitch == "off" then loopOff = true end end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end But the easiest and best way would be to send your string directly as the message -- the computer sending the message modem.send(address, port, "off") -- receiving computer function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, message = event.pull(239, "modem_message") if message == "off" then loopOff = true end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end
  8. Can you post your code and a screenshot of the error message you are getting? This would help alot. I don‘t know exactly what you mean by serialization and why you have problems with the time expiring, but when I had the chance looking at the code I might be able to tell.
  9. Like Molinko said, you need a custom program that will allow you to manipulate another computer. And using network cards might be the best option. There are several ways to write programs that allow sending commands to a second computer; a very naive implementation would use the function load. When passed a string, the string is loaded as a chunk of Lua code and returns a function, that, when called, does whatever was coded in the string. And yes, you need to use event.pull or register a listener via event.listen, but your code needs to "pause" at least every 5 seconds anyways, via event.pull or os.sleep (which is essentially the same as event.pull), so that shouldn't be an issue. So a simple code would look like this: The computer receiving the commands: local event = require "event" while true do local _, _, from, _, _, message = event.pull("modem_message") local res, err_msg = load(message) if not res then -- an error occured while loading the string, so here you can do error management -- like throwing an error and ending the program, printing the error message or write it to a log file, -- ignore the error and continue running the main loop etc print(err_msg) else res() -- on success, load returns a funtion, so call it end end --------------------------------------------------------------------------------- -- if you want to throw an error on failure, using assert would be the way to go --------------------------------------------------------------------------------- local event = require "event" while true do local _, _, from, _, _, message = event.pull("modem_message") assert(load(message))() -- if load returns the function, i.e. loading the string was successfull, the function is called -- when an exception was catched, an error with the error message is thrown end So then you can send a message containing "io.write('test')", and the second computer will execute this task. You can also open files etc, so basically you can do everything remotely. But as I said, this is not a very optimized program since load is quite heavy on the machine since it has to compile the code, but it is probably the most versatile approach. (keep in mind, when you want to use strings inside your code, you need to use the correct quotes, if you wrap your string in ", you can't use " for strings inside, so you need to use ' for example, or you wrap your main string in [[..your code goes here..]] these brackets).
  10. In what piece of code you have 3 ends? I only find 3 ends in the last program I posted. There you have one end for closing the main function (2nd end), one for closing the if-statement (1st end) and the last end is for closing the while loop. And for the error: First it would be good if you could post the actual screenshot. Second, could you post the code of the program you were running? From what I currently see, there‘s propably a typo in line 18, but I can‘t tell exactly, what is wrong until I see the actual code.
  11. Hey, in these if statements, you need to use relational operators. Since you want to see if you're variable is equal to a certain string, you need the '==' (two equal signs). So you're code would look like this -- local require commands start local component= require (“component”) local sides = require(“sides”) local rs = component.redstone local event = require(“event”) -- local os = require(“os”) remove this, the os lib does not need to be required, I think -- local require commands end -- Main function start local function main() local username, message = event.pull(“chat_message”) -- you head a period (.) between both variables -- problematic loop start if username == “Hakz_Studios” and message == “ Alice Refuel” then component.speech_box.say(“Refueling”) component.chat_box.say(“Refueling”) repeat local username,message = event.pull(“chat_message”) rs.setoutput(sides.bottom, 15) -- you need to give the redstone output a value, otherwise it wont turn on -- also, by putting it into a loop, the redstone output will be set a ton of times -- it helps putting the statement before the repeat until loop until username == “Hakz_Studios” and message == “Stop Refueling” -- restarting function function main() -- idk what is this line about, but i dont think it belongs here elseif username == “Hakz_Studios” and message == “Stop Refuel Systems” os.execute(“Shutdown”) -- it will look for a program called 'Shutdown' with a capital S else function main() -- also, dont know what you want to do here, do you want to start the function again (to have the code repeated endlessly) --problematic loop end end -- main function end end Some small info: you don't have to put brackets around your condition in the if-statements, you can, but it's not necessary. Also, here is a program that repeats the main loop over and over again, as I think that is what you want to do in your original code, if I'm wrong tho and misinterpreting you're code, just ignore my suggestion -- require libs local component = require("component") local rs = component.redstone local sides = require("sides") local event = require("event") -- main function local function main() local username, message = event.pull("chat_message") if username == "Hakz_Studios" and message == "Alice Refuel" then component.speech_box.say("Refueling") component.chat_box.say("Refueling") -- this time I set the redstone output once, and then wait for the message 'Stop refueling' then deactivate the redstoneoutput again rs.setOutput(sides.bottom, 15) repeat username, message = event.pull("chat_message") -- you dont have to use 'local' in front of username and message here, since you already created these variables at the top of the main function -- it will override these values but it actually doesnt matter since from this part you will skip to the end and these initial values for both variables -- wont be needed anymore until username == "Hakz_Studios" and message == "Stop Refueling" rs.setOutput(sides.bottom, 0) -- I assume you want to deactivate the redstone after you're done refueling elseif username == "Hakz_Studios" and message == "Stop Refuel System" then os.execute("Shutdown") -- again, this will start the program "Shutdown" with a capital "S" end -- as you can see, we skip the last else statement, as it will call the main function recursively, resulting in a overflow error pretty fast -- you could get away with returning a call to the main function, but this wouldnt be good practice eiter, I guess end -- we add a last while loop, which will repeat endlessly calling the main function while true do main() end I hope this helps. Also you did great for your first shot at programming!
  12. 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...
  13. 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)
  14. 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
  15. @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:)
×
×
  • Create New...

Important Information

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