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

Molinko

Members
  • Content Count

    415
  • Joined

  • Last visited

  • Days Won

    32

Molinko last won the day on April 30

Molinko had the most liked content!

2 Followers

About Molinko

  • Rank
    Leading Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

2032 profile views
  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
×
×
  • Create New...

Important Information

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