This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
xtbs's profile picture

First Attempt at an "OS"

Started by xtbs, 13 November 2016 - 10:03 PM
xtbs #1
Posted 13 November 2016 - 11:03 PM
Hey Everyone, I just got back into programming with CC again and need a little help, (Hopefully not too much)

After installing a couple tech mods I wanted to have a way to handle power management in a sense, more in regards to Pneumaticraft, and while that doesnt have anything to do really with peripherals as far as I am aware (If im wrong please correct me because I would like to know) I am relying a lot off of redstone, and redstone strengths, I wrote a small management program that i have a hard coded value for my maximum pressure, which for testing purposes, is relatively useful. The problem is as I expand my air system to have more devices, compressors, etc… I need to adjust the program accordingly, on top of that I want to add in the use of being able to live view my pressures, flow, and rf generation (for completely unrelated mods).

With that in mind I decided it would be easier to write up an os program that has a basic GUI maybe a couple menu options, but the workload of making sure the compressors dont overproduce has to be running at all times as if the compressors do not shut off half my base will look like the result of a creeper rave.


This is the code i am using currently (i retyped it out so if there are a couple syntax errors please ignore them, it works in game)
really this is what I want to keep running in the background but I would like to be able to show these values on a monitor and be able to change the constant the airPressure is comparing against so that I can raise or lower the total system pressure.

local ventPressure = 7 -- this is to set a compressor vent to release air if it goes over about 4 bar (formula in mod is (Threshold(bar) = 7.5 - Redstone x 0.5)
redstone.setAnalogOutput("back, ventPressure)
while true do
local airPressure = redstone.getAnalogInput("front") -- checks the strength of signal coming from pressure gauge (2x pressure(bar))
if airPressure >= 8 -- 8 is the "Magic" number at this moment, would like this variable to change on user demand
    then
	  redstone.setBundledOutput("right", colors.orange)
	  os.sleep(1)
else if airPressure < 8
	 then
	   redstone.setBundledOutput("right", 0)
end
end
end

So after all this really where i need a guide in the right direction is how to make it so that the program doesnt pause to wait for input on the constant so that the system doesnt blow up, and how to live stream data such as the pressure, and such.

Also one other question, Is there a way to send and receive redstone signal strengths all from a bundled cable on on side of the computer or do I have to run separate sides to determine this.

thanks
Bomb Bloke #2
Posted 13 November 2016 - 11:51 PM
Can't say I've tested it recently, but to my memory "signal strength" and "bundled cables" don't go together. I believe you'd need separate sides for that.

Usually if you wanted to check things on a regular basis, you'd be using os.startTimer() and waiting on the "timer" events. In this case, odds are you'd just be able to call os.pullEvent("redstone") to have your script pause until one of the redstone inputs change.
xtbs #3
Posted 14 November 2016 - 04:25 AM
I dont want anything pausing though, the air system is very touchy and if it goes up by .3 bar it will explode, (at least right now) I want a continuous adjustment of the compressors being on or off.
Bomb Bloke #4
Posted 14 November 2016 - 10:05 AM
If your computer is getting all its input via redstone, then you may as well have your script wait for redstone state changes - if the inputs aren't changing, then what is there for your script to do? Most things in Minecraft only update once per server tick anyways (a twentieth of a second), and redstone signals can only update once per tenth of a second.

On top of that, it may be that you're not going to get the precision you need via redstone signal strength anyways (there's only sixteen possible "strengths", after all). It may well be worth checking to see whether the blocks you're dealing with can be used as peripherals.