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 Molinko

  1. Have you already installed openos or is it running from the disk?
  2. The `require` function is implemented by the OS and is not in the default Lua environment. It needs a filesystem to search for packages and because the eeprom is basically a one file filesystem.. There's nowhere to look for packages. Either install OpenOS or see package.lua from OpenOS source to get an idea for how to write your own require function.
  3. I suspected you might be coming from python :). You might be interested in moonscript. I made a simple patch that allows programs to use the shebang syntax in OpenOS i.e #!/usr/bin/moon for i = 1, 5 print i unless i%2 == 0
  4. It's hard to tell just from what you've described but it sounds like the computer doesn't have an energy source...
  5. There are a couple errors. The first is that the `while` keyword must be lowercase. Also within the `while` loop the if statement is missing the `end` keyword. I believe you'll also need to require the libraries you need before using them in a definition. local component = require "component" local sides = require "sides" local redstone = component.redstone local reactor = component.nc_fission_reactor local function GP() return reactor.getEnergyStored() end local mP, MP = 4000, reactor.getMaxEnergyStored() local MMP, CP = (MP / 4) * 3, GP() while CP > 0 do if CP > MMP then redstone.setOutput(sides.top, 15) elseif CP < mP then redstone.setOutput(sides.top, 0) end CP = GP() -- # don't forget to update the variable value within the loop end
  6. The issue is with your variables returned by event.pull. the 6th rturn value is the message. You're assignment for message is the fifth which is actually distance which will always be 1 from a wired modem.
  7. One way is to convert your script to run as an rc program. The other is to use threads from the thread library, see https://ocdoc.cil.li/api:thread. Here's a simple example.. local thread = require "thread" local proc = thread.create(os.execute, "/path/to/program") proc:detach() -- # detach from current process
  8. Yeah it would.. I missed that. Perhaps a nil check would be better. function m.addTrustedUser(user, level) if db.users[user] ~= nil then error "Cannot add an existing user!" end db.users[user] = level db.hasChanges = true end
  9. Overall the program looks pretty solid. Personally I like to write things with more descriptive names for when I have to revisit programs after a while. One place where things become unclear is using 'k' or 'v' in your pairs loops. If the keys and values are really arbitrary then this makes sense however several places in your code could be clarified by using better variable names. Here's an example.. --- Distribute Json -- Disseminates the settings from the database to all turrets. function m.distribJson() -- # also db.turrets is an array so maybe ipairs would help a reader infer that. _ lets me see the index/key is irrelevant in this loop but perhaps some loop abstraction would be nice? for _,v in pairs(db.turrets) do -- # what exactly is v? maybe this chould be compId or turret_id? for _,player in pairs(toRemove) do component.invoke(v, "removeTrustedPlayer", player) -- # seems v is a uuid(component address)? end for user,priv in pairs(db.users) do -- # like this! this is more clear component.invoke(v, "addTrustedPlayer", user, priv) end for meth,bool in pairs(db.targets) do -- # bool could be more clear. perhaps should_engage or something that describes the variable purpose component.invoke(v, meth, bool) end end toRemove= {} end local privs = { [1] = true, -- # equal to admin [2] = false, -- # generic trusted priv admin = true, -- # named privs are nice to have trusted = false --# maybe 'user' is too generic? perhaps 'basic' or 'trusted'? } function m.addTrustedUser(user, level) if db.users[user] then error "Cannot add an existing user!" end db.users[user] = level db.hasChanges = true end m.addTrustedUser('molinko', privs[2]) -- # or privs.trusted this is nice and readable. m.addTrustedUser('Brodur', privs.admin) -- # I dont have to look at the privs table to see whats happening... Overall your program looks fine. Personally I would just clarify(imply) whats happening a bit more with your variable names and change some to do the same. Nice program though
  10. You should look to the docs. I'm not versed in pub/priv key pairs but I imagine the decrypt function takes either key(but usually the private?) to decrypt encrypted data
  11. A combo of a wrapper and a custom program env might be able to do what you want but you're right that it might just be just a lot of overhead for a few convenience functions.. It also wouldn't cover cases on raw string values like ("yolo"):len()
  12. Capitalization. You're calling 'getDimensionID' and it should be 'getDimensionId'
  13. @Log you beat me to it by about a minute :p. So I'll just add how to get a useful list OP mentioned. local component = require "component" local debug = component.debug local players = {} for _, name in ipairs(debug.getPlayers()) do local world = debug.getPlayer(name).getWorld() table.insert(players, { name = name, dimension = { name = world.getDimensionName(), id = world.getDimensionId() } }) end print(players[1].name, players[1].dimension.name, players[1].dimension.id) --> "Molinko" "overworld" "0"
  14. Molinko

    a nil value

    It seems like you have a test table of `items` and in your original script only the first element of an `item` is a string and the rest are numbers.. However in your test `items` table in the new script your seems to have a typo.. items = {{"minecraft:coal,1,1,1"}} -- # Everything here is one string.. items = {{"minecraft:coal",1,1,1}} -- # This is what I believe you've overlooked
  15. The error you received stems from the second variant of this function. You can call rs.setOutput like so.. -- # with a number side[0-5] and a signal strength rs.setOutput(2, 15) -- # using the sides api but basically the same thing rs.setOutput(sides.east, 15) -- # or by setting multiple sides at the same time by passing a table rs.setOutput({ -- # [sides.west] evaluates to a number side [sides.west] = 15, [sides.south] = 10 })
  16. Pretty sure you need to use the HTTP Request Object API that component.internet.request returns. It is a userdata table with methods. I broke my MC launcher so I cant test this but you can try something along these lines.. Got a chance to test and the below code I have didn't quite work... I've updated it local success, response = pcall(web.request, "<your api call>") if not success then error("Something sucks here..") end local content = "" for chunk in response.read do -- # changed to response.read content = content .. chunk end doStuffWithData(content) -- # yay!?
  17. I would expect that you're somehow overwriting the string lib in your context.. I would recommend using a different variable name for your string value other than `string` as this will probably cause your error later when calling string.format on it.. The result of type(string) by default would normally result in "table" because `string` is a global Lua library.
  18. Molinko

    Hep with my code?

    Can you do me a solid and either point me to the print3d source code or take a screenie of line 70 in OC?
  19. @Nogitsu there is actually already a mod for that called OC glasses and OC glasses 2
  20. I just tried this in OC | MC 1.12.2 | Forge No dice. I guess there is indeed a bug.. Perhaps it was fixed in OC when you tried it.. Bummer
  21. Have you tried it in the tool slot and in an inventory slot(while selected)? I'm gonna try it and get back to you..
  22. Have you tried using the sneaky parameter with robot.use?
  23. I think some form of navigation library and server would be great. Imagine a robot or drone wants to go somewhere in your base. You could write a server that calculates a path from point 'A' to point 'B' and serves a path string (like the one your library uses) back to the robot/drone. Maybe have the server update knowledge of the base layout with a robot / drone using a geolyzer so it can give clear paths to clients. It's a mouthful but could keep other programs very simple and would be very reusable.
  • Create New...

Important Information

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