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

Semi Simple Reactor please help

Started by Knightshadow, 28 October 2012 - 04:46 AM
Knightshadow #1
Posted 28 October 2012 - 05:46 AM
_____________Not In Code__________________
hi im a new to computercraft(1.4) but trying hard to figuer
as much out myself as possible ive gotten to a point
where it runs untill i press Ctrl+T to terminate
but while its running it dose not shutdown or
engage the shields no errors except not sending outputs
ill update this till it works thanks to helpfull ppl :D/>/>

ive broken its up in to 4 files
REShutdown
ROn
RShield
Test
diff inputs tested but same result
problems still not outputing


———————wire in/output—————————–

input:
blue heat 1000
yellow heat 2000


output:
green coolant
white shields

red reactor on/off
atm with a red signal reactor is off (inverter) is easy enough to fix pc crash
and restarts cos i noticed every time i log in on single i have to restart it
___________________________________________________________
Q. can one bundled cable take In and Out or only one?
A.
what is ment to happen is when the reactor is below 1000 the only thing on is
green(coolant) then when it gets to 1000
white(shields) come on and if it gets to 2000 the
REShuntoff turns it off and prevents it from meltdown i was testing
it with out the computer and i can run it with no coolant and leave it
and it will not melt down i acedently made some mfsu's go boom but lol

——————————————————————————————————

File:REShutdown

function REShutdown()
rs.setBundledOutput("back", colors.red)
rs.setBundledOutput("back", colors.white)
rs.setBundledOutput("back", colors.green)
end
function RReset()
rs.setBundledOutput("back", colors.red)
end
print ("Shutting Down")
REShutdown()
sleep(30)
RReset()
sleep(1)
shell.run ("test")

———————————————————————————

File:RShield

function RShield()
rs.setBundledOutput("back", colors.white)
rs.setBundledOutput("back", colors.green)
end
print ("Shield Active")
RShield()
sleep(1)
shell.run ("test")

————————————————————————————

File:ROn

function ROn()
rs.setBundledOutput("back", colors.green)
end
print ("Running")
ROn()
sleep(1)
shell.run ("test")

————————————————————————————–

File:test

os.pullEvent("redstone")
if rs.getBundledInput("back", colors.blue) == true and
rs.getBundledInput("back", colors.yellow) == true then
shell.run ("REShutdown")

elseif rs.getBundledInput("back", colors.blue) == true and
rs.getBundledInput("back", colors.yellow) == false then
shell.run ("RShield")

elseif rs.getBundledInput("back", colors.blue) == false and
rs.getBundledinput("back", colors.yellow) == false then
shell.run ("ROn")
end
brett122798 #2
Posted 28 October 2012 - 05:56 AM
I can tell you one problem with this(not even looking at anything else), you need to define the functions at the top of the code.
Knightshadow #3
Posted 28 October 2012 - 06:01 AM
cool that got rid of the error but not doing anything thanks for the tip
Knightshadow #4
Posted 28 October 2012 - 06:35 AM
k ive done the silly fixes lol like ROn from RRUN and put each function in a file of there own and the ifs are shell.run then when its done that it shell.run test and
if elseif and else but it still dosent work
ChunLing #5
Posted 28 October 2012 - 06:48 AM
Does it run but not do anything or do you have an error? If the latter, post the error and the code.
Knightshadow #6
Posted 28 October 2012 - 07:02 AM
it runs untll i terminate it but atm i have the 1000 and 2000 set at 0 an trying to get REShutoff working but none of them turn on no errors
Knightshadow #7
Posted 28 October 2012 - 08:27 AM
ive also just tryed how ever it dose the same thing no errors but it dosent do anything

os.pullEvent("redstone")
if rs.getBundledInput("back") == 24577 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 10257 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 10256 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 24577 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 8192 then
shell.run ("ROn")
elseif rs.getBundledInput("back") == 10241 then
shell.run ("RShield")
elseif rs.getBundledInput("back") == 2065 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 2049 then
shell.run ("RShield")
elseif rs.getBundledInput("back") == 10240 then
shell.run ("RShield")
sleep(0)
end
ChunLing #8
Posted 28 October 2012 - 09:39 AM
Yeah, you need someone familiar with reactors and sensors and stuff.
1lann #9
Posted 28 October 2012 - 11:40 AM
ive also just tryed how ever it dose the same thing no errors but it dosent do anything

os.pullEvent("redstone")
if rs.getBundledInput("back") == 24577 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 10257 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 10256 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 24577 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 8192 then
shell.run ("ROn")
elseif rs.getBundledInput("back") == 10241 then
shell.run ("RShield")
elseif rs.getBundledInput("back") == 2065 then
shell.run ("REShutdown")
elseif rs.getBundledInput("back") == 2049 then
shell.run ("RShield")
elseif rs.getBundledInput("back") == 10240 then
shell.run ("RShield")
sleep(0)
end
Aren't there only 16 wires in rp2? I have never used bundled cables but theoretically the maximum value for the bundle cable would be 17^2-1 which is 288. There will never be a value above 288 thus none of your conditional statements will ever return true.

Edit: DO'H! Stupid me! It's not 17^2-1. It's 2^17-1
Knightshadow #10
Posted 28 October 2012 - 02:22 PM
those are the numbers i got from redprobe and it told me those numbers but im not shore im new to this
white was 1 yellow was 16 blue 2048 green 8192 red 16384 then like white+blue was 2049 an white blue yellow 2065 green yellow white blue 10257 green red white 24577 all of them 26641
Harcole #11
Posted 28 October 2012 - 03:05 PM
Use the colors API to solve your problem of numbers, this also allows you to specify cable colours at the top and use variable names through out your script… I've just finished my reactor control program and posted it in to this post: http://www.computerc...cking-contents/ I don't know if you'll find anything helpful/useful in that?

Yes there are only 16 cables but the maximum value is 32,768 (http://computercraft...le=Colors_(API)) color.black being that particular value.

Your test for a signal is wrong:

colors.test(rs.getBundledInput(<side>), <wire_value>)
returns true or false;

as such, from your code above this line performs "RShield"

if colors.test(rs.getBundledInput("back"), colors.purple) then
	shell.run("RShield");
	sleep(1); -- pause for 1 second (sleep(0) does nothing)
end


or as your entire script altered:


os.pullEvent("redstone");

if colors.test(rs.getBundledInput("back"), colors.red + colors.green + colors.white) then -- by adding all those colours we get your original value, not sure that is what you wanted, but proves concept
	shell.run ("REShutdown");

elseif colors.test(rs.getBundledInput("back"), colors.green + colors.blue +  colors.yellow + colors.white) then
	shell.run ("REShutdown");

elseif colors.test(rs.getBundledInput("back"), colors.green + colors.blue +  colors.yellow) then
   shell.run ("REShutdown");

elseif colors.test(rs.getBundledInput("back"), colors.red + colors.green + colors.white) then
	shell.run ("REShutdown");

elseif colors.test(rs.getBundledInput("back"), colors.green) then
	shell.run ("ROn");

elseif colors.test(rs.getBundledInput("back"), colors.blue + colors.yellow +  colors.white) then
	shell.run ("RShield");

elseif colors.test(rs.getBundledInput("back"), colors.green + colors.blue +  colors.yellow) then
	shell.run ("REShutdown");

elseif colors.test(rs.getBundledInput("back"), colors.blue +  colors.white) then
	shell.run ("RShield");

elseif colors.test(rs.getBundledInput("back"), colors.green + colors.blue) then
	shell.run ("RShield");

end
Knightshadow #12
Posted 31 October 2012 - 11:05 AM
ive tryed colors.test(rs.getBundledInput(<side>), <wire_value>) aswell now but it still just dose the same as the code i have up allready it gets the signals but it dosent do anything
Harcole #13
Posted 31 October 2012 - 11:15 AM
Can you post the script that is called by Shell so we can see what that script is/does please?

Alternatively ensure that the redstone signal output is triggered along the lines of this:


redstone.setBundledOutput(<string_side>, colors.<color_name>);

Again, you can add colors at the end to give more than one signal ouptut eg.


redstone.setBundledOutput(<string_side>, colors.<color_name> + colors.<color_name>)

More information here: http://computercraft.info/wiki/index.php?title=Redstone_(API)
Knightshadow #14
Posted 31 October 2012 - 11:36 AM
yeah there up there above the code each File: is a diff file called on by shell
just curious this might be the proble can u use one bundled cable for in and out or do i need 2 bundled cables
thanks heeps for the link to :P/>/>
Harcole #15
Posted 31 October 2012 - 12:03 PM
Sorry was being blind and reading too far down the thread!

File:ROn (Fixed slightly, removed ROn() from its own function call and instead call it just above sleep(0))


function ROn()
	rs.setBundledOutput("back", colors.green) -- turns on the green cable only, if any other cables were on they are now off.
end

ROn() -- Calling it here is what I think you were aiming for;
sleep(0)
shell.run ("test")

File:test


os.pullEvent("redstone")

if colors.test(rs.getBundledInput("back"), colors.red) and colors.test(rs.getBundledInput("back"), colors.yellow) then
	shell.run ("REShutdown")

elseif colors.test(rs.getBundledInput("back"), colors.blue) and ~colors.test(rs.getBundledInput("back"), colors.yellow) then
	shell.run ("RShield")

elseif ~colors.test(rs.getBundledInput("back"), colors.blue) and ~colors.test(rs.getBundledInput("back"), colors.yellow) then
	shell.run ("ROn")
end

If ROn is called and ran, then the only thing in the test file that will be called is ROn again as the only cable that will be light (enabled) is green.

I may be using incorrect syntax with "~" but I'm sure that means "not" so ~colors.test(rs.getBundledInput("back"), colors.blue) should be the same as == false. use which ever you prefer.

Edit: Removed my comment by the sleep(0) line as I just learned that this can prevent issues! My bad :P/>/>
Edited on 31 October 2012 - 01:33 PM
Knightshadow #16
Posted 31 October 2012 - 03:21 PM
apparently ~ is unexspected im useing cc os(1.4) if that makes any diff
Harcole #17
Posted 31 October 2012 - 03:51 PM
http://computercraft.info/wiki/index.php?title=Conditional_statements

Apologies, that link shows I got it wrong… remove the ~ from the start of the line and instead have this and I'll stop trying to apply different language techniques to Lua! (sorry!):


elseif colors.test(rs.getBundledInput("back"), colors.blue) == false and colors.test(rs.getBundledInput("back"), colors.yellow) == false then
	    shell.run ("ROn")
end
Knightshadow #18
Posted 31 October 2012 - 03:59 PM
lol it's all good i appreciate the help
Knightshadow #19
Posted 31 October 2012 - 04:15 PM
i tested that but same thing no red green or white on

os.pullEvent("redstone")
if colors.test(rs.getBundledInput("back"), colors.blue) == true and
colors.test(rs.getBundledInput("back"), colors.yellow) == true then
shell.run ("REshutoff")
elseif colors.test(rs.getBundledInput("back"), colors.blue) == true and
colors.test(rs.getBundledInput("back"), colors.yellow) == false then
shell.run ("RShield")
elseif colors.test(rs.getBundledInput("back"), colors.blue) == false and
colors.test(rs.getBundledInput("back"), colors.yellow) == false then
shell.run ("ROn")end
Harcole #20
Posted 31 October 2012 - 04:27 PM
Add some print lines to the if statements to see if we can get those to display:


elseif colors.test(rs.getBundledInput("back"), colors.blue) == false and colors.test(rs.getBundledInput("back"), colors.yellow) == false then
    print("Run ROn");
    shell.run ("ROn")
end

This will let us see if its a logic fault or if something somewhere is turning everything off before we can see it! The print command will display on the terminal unless you've redirected it to a monitor, in which case it'll show there instead!
Knightshadow #21
Posted 31 October 2012 - 04:41 PM
i just tested it then an it didnt print anything
Harcole #22
Posted 31 October 2012 - 07:40 PM
OK I'm going with a logic fault, having read your original post again and taking the information there, this is the program I wrote that will achieve what you ask. I made some assumption about how you were feeding the coolant, if you don't need the signal to pulse it stops at the last elseif above the double comment line.


-- Input Wires:
-- Blue = Heat > 1000
-- Yellow = Heat > 2000

-- Output Wires:
-- Green = Coolant feed
-- White = Shields
-- Red = Reactor Master Off/On

-- using this to get below 1000 heat before brining the reactor back on line
local restart = true;

-- Keep the program running forever
while true do
if colors.test(rs.getBundledInput("back"), colors.blue) and restart == true then
  -- Heat >1000 turn on coolant
  rs.setBundledOutput("back", colors.green);

  -- Let the people know things are cooling
  print("Coolant feed: ON");

elseif colors.test(rs.getBundledInput("back"), colors.yellow) then
  -- Heat > 2000 so both yellow and blue are actually lit, but we only need to check the highest value
  -- but we must turn on the ice request and the shields, also shutdown the reactor
  rs.setBundledOutput("back", colors.green + colors.white + colors.red);

  -- stop the reactor starting once temprature drops below 2000
  restart = false;

  -- tell someone whats happening
  print("Upper Temp. reached, emergency shutdown in effect. Shields are up, reactor is offline and coolant is enabled.");
elseif colors.test(rs.getBundledInput("back"), colors.blue) == false and restart == false then
  -- restart the reactor as things are safe once again!
  rs.setBundledOuput("back", 0);

  -- restart the reactor update change
  restart = true;

end

-- I've not noticed how your dealing with your coolant, if your enabling a timer then we don't need to do anything else.
-- if however your wanting to trigger a transposer/filter/retirever etc, then we need to pulse the cable

-- pause half a second
sleep(0.5);

-- test to see if the reactor should be on or off, if off assume that the shield should be up
if colors.test(rs.getBundledInput("back"), colors.red) then
  -- the reactor signal must be kept on (To keep reactor off)
  rs.setBundledOutput("back", colors.red + colors.white);

  -- this resets all other cables to off except the red and white cable, keeping the reactor off and shields up

else
  -- all cables are to be turned off
  rs.setBundledOutput("back", 0);

  -- pause half a second
  sleep(0.5);

end

end
Knightshadow #23
Posted 08 November 2012 - 05:55 AM
thats awesome thanks so much there is only one problem if the blue is on when the yellow comes on it dosnt change what its doing like keeps running or keeps shuting off it yellow only is on but if both are on it is running
Harcole #24
Posted 08 November 2012 - 06:56 AM
Moving house this week and offline, I'll look in to this Sunday when I should have my computer unpacked again and post Monday when I'm in work with an update, unless someone is able to look at it sooner…?
Knightshadow #25
Posted 08 November 2012 - 07:25 AM
not a problem