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

Need some help with my reactor on/off program

Started by mikejr222, 29 December 2015 - 11:00 PM
mikejr222 #1
Posted 30 December 2015 - 12:00 AM
Im trying to make a MFSU detector that emits a red stone signal when its above/below a certain EU amount %.
ive tryed looking around for a base script to edit to my setup but all i can find are outputing to monitors :/



Spoilermf = peripheral.wrap("left")
local turnOnAt = 50
local turnOffAt = 90
local euStored = 0
local euMax = 0
local euStoredPercent = 0
local reactorON = redstone.setOutput("right", true)
local reactorOFF = redstone.setOutput("right", false)

function checkeu()
euStored = mf.getEUStored()
euMax = mf.getEUCapacity()
euStoredPercent = math.floor((euStored/euMax)*100)
sleep(0.1)
end

function Power()
if euStoredPercent() < turnOnAt() then
reactorON
else euStoredPercent() > turnOffAt() then
reactorOFF
end
end

——————————–
while true do
checkeu()
Power()
sleep(1)
end
Lupus590 #2
Posted 30 December 2015 - 01:22 AM
turnOnAt and turnOffAt are not functions, also reactorON and reactorOFF do nothing in the code

and please use code tags
Edited on 30 December 2015 - 12:23 AM
HPWebcamAble #3
Posted 30 December 2015 - 03:14 AM
The computer needs a way to know how much EU is in the MFSU, and how much the MFSU can store.

Based on your code, it looks like those functions are 'getEUStored' and 'getEUCapacity'
I'll assume these are correct. If you aren't sure, you can use my Get Methods program to find out what functions the MFSU has


Anyway, here's one way to do it:

--# Declare all our variables
local redstoneSide = "right"
local mfsu = peripheral.wrap("left")
local turnOnAt = 50
local turnOffAt = 90
local capacity = mfsu.getEUCapacity()
local stored,percentage --# Tell Lua that we want these to be local, we'll use them later

--# In an infinite loop...
while true do
  stored = mfsu.getEUStored() --# Get the current level of EU

  percentage = math.floor( stored/capacity * 100 ) --# Calculate the current percentage

  if percentage > turnOnAt and percentage < turnOffAt then --# Is the percentage more than 'turnOnAt' and also less than 'turnOffAt'?
	redstone.setOutput(redstoneSide,true) --# If it is, turn on the redstone
  else
	redstone.setOutput(redstoneSide,false) --# Otherwise, turn it off
  end

  sleep(1) --# This pauses the program for a second, no need to update too often
end

If you have any questions, feel free to ask!
Also if anyone spots any mistakes let me know (I haven't tested this ;P )
Edited on 30 December 2015 - 02:17 AM