Jump to content




Need some help with my reactor on/off program


  • You cannot reply to this topic
2 replies to this topic

#1 mikejr222

  • New Members
  • 1 posts

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 :/



Spoiler


#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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 [code]

Edited by Lupus590, 30 December 2015 - 01:23 AM.


#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

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 by HPWebcamAble, 30 December 2015 - 03:17 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users