This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Tekkit Classic, Computercraft and ccSensors
Started by logan2611, 27 September 2014 - 04:41 PMPosted 27 September 2014 - 06:41 PM
Ok so I am playing tekkit classic and I want my computer to send out a redstone signal when an mfsu is below 50% charge using ccSensors. I have tried this however I can't really figure out the code very well.
Posted 27 September 2014 - 08:59 PM
Post your code and we can see where you went wrong. Sometimes you just need a nudge in the right direction.
Posted 27 September 2014 - 10:15 PM
I would post my code, however my computer has seemed to crash and I forgot to save it. I really wish I would have though.Post your code and we can see where you went wrong. Sometimes you just need a nudge in the right direction.
Posted 27 September 2014 - 11:02 PM
Well then, I don't remember the exact command to get the energy levels from an mfsu. What side is the MFSU connected on?
Posted 28 September 2014 - 12:46 AM
I do not understand what you mean by which side is it connected to. Could you be more specific?
Posted 28 September 2014 - 01:09 AM
What are you using to connect to the MFSU, and where is it plugged into the computer from.
Posted 28 September 2014 - 01:18 AM
The MFSU is getting power from a nuclear reactor and is connected to the computer via ccSensors.
EDIT: I got the physical part sorted out, I just need to make code work
EDIT: I got the physical part sorted out, I just need to make code work
Edited on 27 September 2014 - 11:19 PM
Posted 28 September 2014 - 01:23 AM
What side is the connection from ccSensors, that will help me with helping you.
Posted 28 September 2014 - 01:24 AM
The sensor controller is connected on the left side of the computer
Posted 29 September 2014 - 03:09 AM
Okay so messing around with the sensor controller in a single player tekkit classic world, you can use this code to get the energy stored inside of an MFSU connected to the sensor controller.
If you want a really easy thing just to use to get the energy stored use this.
And then you could easily get the energy level as a variable using
local sSide = "left" --# change this to whatever side the controller block is
local sensorName = "Sensor" --#Change this to the name you set the sensor on the MFSU to be
local sensor = peripheral.wrap(sSide)
local sensorData = {sensor.getSensorReading(sensorName)} --# Puts all the data that the sensor has into a table.
print(sensorData[6]) --# This prints the current energy level, you want to use sensorData[6] whenever you're referencing the energy level, any other number will not be the energy level
Okay so this code is flawed in a way, first thing, if you want to keep a constant knowledge of the energy level you're going to need to use this whenever you want the current energy level
sensorData = {sensor.getSensorReading(sensorName)}
If you don't use that when you want the current level then you're going to get an old inacurate level. Finally to be safe i would use tonumber on sensorData[6] so that you can tell if it's greater than or less than some limits for the energy levels. You could potentially use
if tonumber(sensorData[6]) <= (tonumber(sensorData[4]) / 2) then --# If the current energy is less than or equal to the max energy divided by 2 then
--#Do stuff
else
--#Do other stuff
end
Now anything that has quotes around it, you want to keep the quotes if you're going to change that.If you want a really easy thing just to use to get the energy stored use this.
local sSide = "left"
local sensorName = "Sensor"
local sensor = peripheral.wrap(sSide)
local function getEnergyLevel()
local tableData = {sensor.getSensorReading(sensorName)
return tonumber(tableData[6])
end
And then you could easily get the energy level as a variable using
local currentEnergy = getEnergyLevel()
Edited on 29 September 2014 - 02:44 AM
Posted 29 September 2014 - 05:18 AM
Hey thanks dude I will try it in SP tomorrow. :)/>
Posted 29 September 2014 - 06:21 AM
Alright, if you need more help, i'll be happy to try to help you outHey thanks dude I will try it in SP tomorrow. :)/>
Posted 30 September 2014 - 12:27 AM
Alright, if you need more help, i'll be happy to try to help you outHey thanks dude I will try it in SP tomorrow. :)/>
Hey I just tried the code and all it outputs is -3229?
Also tonumber(sensorData[6]) <= (tonumber(sensorData[4]) gives me
startup:10: attempt to preform arithmetic __div on nil and number
However changing it to 6 makes it work(but outputs -3229 reguardless of settings)
Edited on 29 September 2014 - 10:28 PM
Posted 30 September 2014 - 12:36 AM
You have the correct sensor card in the sensor attached to the mfsu right? Post your current code so i can test it myself.
Posted 30 September 2014 - 12:40 AM
local sSide = "left"
local sensorName = "Sensor"
local sensor - peripheral.wrap(sSide)
local sensorData = {sensors.getSensorReading(sensorName)}
while true do
sensorData = {sensor.getSensorReading(sensorName)}
print(sensorData[6])
if tonumber(sensorData[6]) <= (tonumber(sensorData[6]) / 2) then
redstone.setOutput("right", true)
else
redstone.setOutput("right", false)
Edited on 29 September 2014 - 10:40 PM
Posted 30 September 2014 - 12:44 AM
All right looking at your code, did you copy and paste, or did you attempt to type it out from reading, because a couple things are spelled wrong and would not let it work, (i'm looking at you line 4) and you do not have ends for your loop and if statement, and sensorData[6] will never be less than half of itself. What does your setup look like?
Posted 30 September 2014 - 12:47 AM
All right looking at your code, did you copy and paste, or did you attempt to type it out from reading, because a couple things are spelled wrong and would not let it work, (i'm looking at you line 4) and you do not have ends for your loop and if statement, and sensorData[6] will never be less than half of itself. What does your setup look like?
Well I did make a few mistakes when typing it back into the forums. But I will look over it.
Posted 30 September 2014 - 12:52 AM
Alright, if you need more help, i'll be happy to try to help you outHey thanks dude I will try it in SP tomorrow. :)/>
Hey I just tried the code and all it outputs is -3229?
Also tonumber(sensorData[6]) <= (tonumber(sensorData[4]) gives me
startup:10: attempt to preform arithmetic __div on nil and number
However changing it to 6 makes it work(but outputs -3229 reguardless of settings)
Posted 30 September 2014 - 02:29 AM
All right i know the problem, First, your sensor is not set up right as it doesn't have a transmitter card nor sensor card in it. Secondly, you need to access the sensor connected to the mfsu and press the down arrow key until it's highlighted over EUstorage and press the right arrow key. Then once that's done, it should work correctly. Also you should add sleep(0) after your redstone.setOutput()'s
Edited on 30 September 2014 - 12:30 AM
Posted 30 September 2014 - 03:27 AM
Same error as before, although you were right about it not being setupAll right i know the problem, First, your sensor is not set up right as it doesn't have a transmitter card nor sensor card in it. Secondly, you need to access the sensor connected to the mfsu and press the down arrow key until it's highlighted over EUstorage and press the right arrow key. Then once that's done, it should work correctly. Also you should add sleep(0) after your redstone.setOutput()'s
I will try to see if using the API loading commands will work
EDIT: No effect
Edited on 30 September 2014 - 01:39 AM
Posted 30 September 2014 - 06:34 AM
This is the code i had and it works perfectly for the current purposes.
local sSide = "left"
local sensorName = "Sensor"
local sensor = peripheral.wrap(sSide)
local sensorData = {sensor.getSensorReading(sensorName)}
while true do
sensorData = {sensor.getSensorReading(sensorName)}
if tonumber(sensorData[6]) <= (tonumber(sensorData[4])/2) then
redstone.setOutput("right",true)
sleep(0)
else
redstone.setOutputs("right",false)
sleep(0)
end
end