- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
-
Content Count
451 -
Joined
-
Last visited
-
Days Won
35
Posts posted by Molinko
-
-
1) yes. The quotes.
2) autorun isn't depricated ( I don't think..) but you might like the .shrc format better.
Run 'edit .shrc' in the home dir and add the path to the file you want to run on the first available line. It's super simple and can have multiple programs to run on startup. Also programs can take shell args just like typing it in yourself.
-
I'm not super familiar with this library so you may have to adjust the code as it is untested.
local GUI = require("GUI") local component = require 'component' local thread = require 'thread' local event = require 'event' local reactor = component.reactor_chamber local currentTemps = reactor.getHeat() -------------------------------------------------------------------------------- -- Create new application local application = GUI.application() -- Add panel that fits application application:addChild(GUI.panel(1, 1, application.width, application.height, 0x262626)) -- Add smaller panels application:addChild(GUI.panel(4, 2, 23, 4, 0x880000)) application:addChild(GUI.text(5, 3, 0xFFFFFF, "Current Reactor Temps")) -- Grab a reference to the text object you need to update local gui_temp = GUI.text(5, 5, 0xFFFFFF, currentTemps) application:addChild(gui_temp) -- Create a timer that will run every 3 seconds, forever. local tid = event.timer(3, function() gui_temp.text = tostring(reactor.getHeat()) -- overwrite the text data gui_temp:update() -- notify the app that the state of gui_temp has changed end, math.huge) -------------------------------------------------------------------------------- application:draw(true) application:start() event.cancel(tid) -- cleanup the timer after application:start returns
-
The issue you see here is because `component` is removed from the global scope in OpenOS and must be required using the `require` function. If this file is intended to be run from an eeprom at boot instead of the standard Lua bios then `component` will still be global and this issue shouldn't remain. Running this program from the shell (as you're doing in the picture).. it will be provided an environment that doesn't contain the `component` namespace. This program seems to be intended to only run from a computer with seemingly multiple screens and gpus, cpu, redstone block(or card?), ram, and of course an eeprom. No hdd and no OS(no OpenOS floppy either).
-
On line 349 and others you use an undeclared variable named 'turbineNum' to index the turbine table like so "some_value = turbine[turbineNum].someMethod()".
You use this in a few places in the script yet I can't find a placed where it is defined.
-
It's not possible. You can set them one after the other, sequentially, fast enough that you won't notice. Effectively at the same time.. but parallelization is not possible
-
If you could post all the code or explain what you're trying to do a bit more that would help me help you.
Lua is single threaded so there isn't any real parallelization, so I'm having a hard time understanding what you need.
-
Nm I can't read..
-
Typically the GUI and your application are separated because of the reactive nature of the GUI library. Most of your code for reacting to GUI events will go into a GUIObjects event handler.
-- # ... myButton.eventHandler = function(app, instance, event) if event == "touch" then -- # react to touch event. Alter state, etc... end end
I don't have the time to test this my self but you could try using OpenOS threads to give control back to your main script.
-- # ... more stuff up here local thread = require 'thread' -- # Gui logic n stuff... -- # This will now run whenever the main script yields i.e event.pulls, os.sleeps, etc.. local guiProc = thread.create(application.start, application) -- # Continue below with main program runtime logic. -- # Be aware that the GUI will only be able to process stuff when this main script yields as Lua is single threaded
Multiline text is handled by GUI.textBox rather than GUI.text as far as I can tell.
Hope this helps you over the initial hump. Happy to help more if you still need it
-
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
-
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"
-
Have you already installed openos or is it running from the disk?
-
-
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.
-
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
-
It's hard to tell just from what you've described but it sounds like the computer doesn't have an energy source...
-
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
-
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.
-
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
-
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
-
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
-
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
-
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()
-
Capitalization. You're calling 'getDimensionID' and it should be 'getDimensionId'
-
@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"
Updating items on screen
in Programming
Posted
This is just another attempt in case I missed something... If this doesn't work yet again, then could you run `cat /tmp/event.log` after running this (if it fails), and reply with its output if it's available. Threads and event timers don't throw errors in the main process.