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. Try this out.. The require function is defined by OpenOS which isn't available in the drone env. require is used to load libraries from the package path. See /lib/package.lua local drone = component.proxy(component.list('drone')()) local position = component.proxy(component.list('navigation')()).getPosition() -- # The require keyword is for libraries accessed via a filesystem which the drone doesn't have. Therefor it isn't available. -- # The `component.someComponentName` functionality is defined in the OpenOS component library.. Again, not available here. if position ~= nil then drone.setStatusText("We in business bb") end while true do drone.move(0, 0, 0) -- to keep the drone running end Drones can be a bit of a pain to get used to as they dont have any of the sweet libs defined in OpenOS. See https://ocdoc.cil.li/tutorial:custom_oses to see what is available in a hardware only env like drones or and hw that is without an OS
  2. Molinko

    RC Arguments

    RC args are accessible from the start method in your startup.lua module under the args env name. Its a little complicated but basically when your startup rc module is loaded the rc.cfg variable with the same name (startup) is accessible as args in your module. -- # rc.cfg enabled = {"startup"} startup = {} -- # this table notation requires quotes btw startup["col0"] = 0xFF9200 startup["col1"] = 0xFF6D00 startup["col2"] = 0x000000 startup["col3"] = 0xFFFFC0 -- # /etc/rc.d/startup.lua local gpu = require("component").gpu function start(cfgColor, text) local color = args[cfgColor] -- # the `args` table here is your `startup` table as defined in /etc/rc.cfg local ofg = gpu.setForeground(color) print(text) gpu.setForeground(ofg) end -- # call start from the cmd line like so.. -- > rc startup start col2 "this is colored text"
  3. Have you already installed openos or is it running from the disk?
  4. 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.
  5. 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
  6. It's hard to tell just from what you've described but it sounds like the computer doesn't have an energy source...
  7. 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
  8. 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.
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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()
  14. Capitalization. You're calling 'getDimensionID' and it should be 'getDimensionId'
  15. @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"
  16. 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
  17. 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 })
  18. 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!?
  19. 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.
  20. 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?
  21. @Nogitsu there is actually already a mod for that called OC glasses and OC glasses 2
  22. 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
  23. 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..
  • Create New...

Important Information

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