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

Print on redstone input?

Started by fergregerg, 06 July 2012 - 03:46 PM
fergregerg #1
Posted 06 July 2012 - 05:46 PM
Well i have tried many things this is what i have. i want it to tell me weather or not redstone is connected (true false)

local inputside = "back"
os.pullEvent("redstone")
if rs.getInput(inputside) then
print("Redstone : True")
else
print("Redstone : False")
end
term.restore()
MysticT #2
Posted 06 July 2012 - 05:48 PM
You forgot the closing bracket here:

os.pullEvent("redstone"
It should be:

os.pullEvent("redstone")

Also, the last line shouldn't be there, since you never redirected the terminal output.
fergregerg #3
Posted 06 July 2012 - 05:55 PM
yeah i just forgot the bracket in this post but when i run it nothing happens.
Lyqyd #4
Posted 06 July 2012 - 06:25 PM
Are you changing the state of the redstone input after you start the program?
fergregerg #5
Posted 06 July 2012 - 07:37 PM
thanks MysticT and lyqyd but now i have a different problem. i set the values of redstone and i want 2 add it. like left + right
true = 10000000 false = 0
but if i change the redstone on the left first then it will say its the back because its first
also when i add i get an error



local inputside = "back"
os.pullEvent("redstone")
if rs.getInput(inputside) then
print("Redstone: True")
local input1 = 10000000
else
print("Redstone: False")
local input1 = 0
end

local cp1left = "left"
os.pullEvent("redstone")
if rs.getInput(cp1left) then
print("Redstone left: True")
local input2 = 10000000
else
print("Redstone left: False")
local input2 = 0
end

local EU = ((input1)+(input2))
print("Storage contains (EU) EU")
OmegaVest #6
Posted 06 July 2012 - 08:06 PM
Alright, your first problem is that you are calling both sides separately.

So, do something like this:

local inputside = "back"
locak cp1left = "left"

local roughTot = 0
local full = 10000000
event, arg1, arg2 = os.pullevent("redstone")
if rs.getInput(inputside) then
   print("RS: True")
   roughTot = roughTot + full
else
   print("RS: False")
end
if rs.getInput(cp1left) then
   print("RS Left: True")
   roughTot = roughTot + full
else
   print("RS Left: False"
end

print("Storage contains ", roughTot, " EU, approx.")


That way, it does not stop and look for a signal after it has already found one. It will merely check for a change, and then reset its numbers when it does.
fergregerg #7
Posted 06 July 2012 - 08:45 PM
thanks omegavest it helped me get the adding down. i think i should explain my whole idea of what im doing. As some people may have been able to tell from the EU i am trying to receive a redstone signal from more then one MFSU. I dont want it to stop when it gets ones side. if more then 1 side has redstone i want it to add 10000000 + 10000000 and give me 20000000. i will eventually put this on a network and in all my storage places i will have them add it up and display a close amount of how much EU is currently stored. Is it possible to get the redstone signal without having to change it? is it possible to just stay running and if a signal is subtracted then it subtracks 10000000 from the amount. Eventually i will put it on a monitor but im going step by step. Now im not tying to get you guys to give me all the code thats not what im asking for, i just need to be pointed in the right direction

edit ok i did it wrong so it does add the 2 sides after changing 1 side
OmegaVest #8
Posted 06 July 2012 - 09:01 PM
Hmm. Well, first I should ask this: are you using RedPower2? If you are not, give it a look. The bundled cables will make it incredibly easy to track much larger amounts of EU storage blocks. Annnnnd, it is possible to do this without an event pull. Use a while loop with a sleep at its end. Probably a clear as well. Term API for that.

Furthermore, I think it would be simpler to have it done this way than trying to make a variable that stays active forever. When you start subtracting, you start adding lines about whether or not the inputs changed, and that gets complicated, or at the very least long and memory-heavy.
fergregerg #9
Posted 06 July 2012 - 09:13 PM
MFSU gives off redstone power at full capacity, does it give it out to redpower bundle cables? if not how would u get it without an event pull?
in this case id be able to just keep updating the amount on the monitor everytime it changed as it just keept checking in a loop and
term.clear() at the end?
OmegaVest #10
Posted 06 July 2012 - 09:27 PM
Use rs.getInput(). It does not need an event to trigger it. My above code (mistakes notwithstanding), will work without its event pull, if you put it in a while loop, with a sleep at the end. And yes, term.clear(), but make sure you use term.setCursorPos(1,1) after that.

And, I said look at the bundled cables. It will take a bit before we can get there. Take a look at the wiki, specifically the RS API.

Basically, bundled cables connect insulated redstone wires to the computer (for our purposes, anyway). Put a white wire end next to an MFSU, then put the white wire to a bundled cable, then the cable into a computer. Then, when you call rs.getBundledInput(), if the wire is on (MFSU full), it should output 1. And you can have up to 16 wires in one bundle, so with a two-sided check, you can have 32 MFSUs connected and checked at once.
fergregerg #11
Posted 06 July 2012 - 10:24 PM
Uhm ok so would it be something like this then? Also i dont understand how to add loops even after looking at tutorials


local inputside = "back"
local cp1left = "left"

local EUamount = 0
local full = 10000000
if rs.testBundledInput(inputside, 1) then
   print("RS: True")
   EUamount = EUamount + full
else
   print("RS: False")
end
if rs.testBundledInput(cp1left, 1) then
   print("RS Left: True")
  EUamount = EUamount + full
else
   print("RS Left: False")
end

print("Storage contains ", EUamount, " EU, approx.")
OmegaVest #12
Posted 06 July 2012 - 11:01 PM
Alright, so loops are actually fairly simple. The easiest one is an endless while loop.


while true do	-- The "true" can be any conditional, such as loopNum < 9

   -- Code Here. I'd suggest starting after the two top variables.

   sleep (0.5)   -- Needed so the loop won't crash.
   term.clear()
   term.setCursorPos(1,1)   --These two so you can reset the screen.
end

But otherwise, everything is right.


Oh, and you can set the 0.5 in the sleep call to any number, and it will sleep for that many seconds before restarting the loop.
fergregerg #13
Posted 06 July 2012 - 11:33 PM
ok before i start the loop again i would rather do it with redpower and i cant seem to get it to work. is it testBundleInput(inputside, 1) or testBundleInput(inputside, white) or do i have to create the int in which how do i do that? also the first 2 things i said i got the error 7: attempt to call nil
fergregerg #14
Posted 07 July 2012 - 12:17 AM
NOW FOR MONITOR!


while true do
local inputside = "back"
local cp1left = "left"

local EUamount = 0
local full = 10000000
if rs.testBundledInput(inputside, colors.white) == true then
   print("RS: True")
   EUamount = EUamount + full
else
   print("RS: False")
end
if rs.testBundledInput(cp1left, colors.black) == true then
   print("RS Left: True")
  EUamount = EUamount + full
else
   print("RS Left: False")
end

print("Storage contains ", EUamount, " EU, approx.")
rednet.recieve(10)
end
OmegaVest #15
Posted 07 July 2012 - 03:04 AM
That should work. Though, you can use one bundle for multiple inputs, if you want.

For monitors, you need to look at the peripheral api. First, wrap the monitor, then either redirect, or use your monitor variable in place of term API commands.

So, term.write() becomes mon.write()

Redirection is a more brute-force version, which makes all your term commands affect the monitor only.
fergregerg #16
Posted 08 July 2012 - 05:57 AM
ok now that i got my monitor all set up i have a problem print("Storage contains ", EUamount, " EU, approx.") works but
mon.write("Storage contains ", EUamount, " EU, approx.") only shows "Storage contains" on the screen any help?
fergregerg #17
Posted 08 July 2012 - 06:13 AM
ok got that working but now it says 1.0E7 for 10 million
mon.write(EUamount)
OmegaVest #18
Posted 09 July 2012 - 04:07 PM
Hmm. Try splitting up the writes. So, like this:


mon.write("Storage contains: ")
mon.write(EUamount)
mon.write(" EU, approx.")


This will put them all on the same line, since write does not add an end-of-line character to the string, and this is more or less what print does, though with term. instead of mon.