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

New to ComputerCraft

Started by DarkSleep, 16 March 2014 - 03:44 PM
DarkSleep #1
Posted 16 March 2014 - 04:44 PM
Hey i am very new to computer craft codeing
i am haveing some idea for program i would like to make

it seems very easy

Idea is when computer get Redstone signel From Radar It will display Missile in coming

========================
+ +
+ Missile Incomeing!! +
+ +
+ ~Power Up Force Field~ + <—- This is what i whant to post to the monitors 3x3
+ +
========================


I just needing help How can i make it post this when red stone signal it turn on
i got alarm And got big reactor to turn of to power the force field

So if you can point me in right way thanks
CometWolf #2
Posted 16 March 2014 - 09:59 PM
Try reading up on stuff on the wiki.
http://computercraft.info/wiki/Redstone_%28API%29 redstone
http://computercraft.info/wiki/Monitor monitor
http://computercraft.info/wiki/Os.pullEvent events, not really needed but if you want to do it properly, you have to use these.
Angel_Code #3
Posted 19 March 2014 - 04:03 AM
ok so if i'm understanding this you want a program that when your computer is receiving a redstone signal
it will print some text to a monitor and then output a redstone signal on a different side to activate your forcefield?

i will try to work something out for you and will reply once i have somthing
Angel_Code #4
Posted 19 March 2014 - 11:40 PM
Ok i hope this is what you're looking for
Image:
Spoiler
Code:
SpoilerPastebin link:
http://pastebin.com/1x5SqpMU

to install on cc-Computer type
pastebin get 1x5SqpMU defence

--=========================================================================================================
--DoNot remove this Credits
--Created On 19th MARCH 2014 
--by Angel_Code http://www.computercraft.info/forums2/index.php?/user/18955-angel-code/
--Support Provided By theoriginalbit http://computercraft.theoriginalbit.com/
--Support Provided By Bomb Bloke http://www.computercraft.info/forums2/index.php?/user/15121-bomb-bloke/
--=========================================================================================================
Mon = peripheral.wrap("top")  --Change "top" to the side the monitor is on.
local function centerText(text)
  x,y = Mon.getSize()
  x1,y1 = Mon.getCursorPos()
  Mon.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  Mon.write(text)  
end

local function defence()
    Mon.clear()
    Mon.setCursorPos(1, 1)
    centerText("=========================================")
    Mon.setCursorPos(1, 2)
    centerText("WARNING!")
    Mon.setCursorPos(1, 3)
    centerText("INCOMING MISSILE")
    Mon.setCursorPos(1, 4)
    centerText("ACTIVATING FORCEFIELD")
    redstone.setOutput("right", true) --Change "right" to the OUTPUT side.
    Mon.setCursorPos(1, 6)
    centerText("=========================================")

    local count = 60 -- Change 60 to the amout of time in seconds a redstone signal should be turned on for.
while true do
  Mon.setCursorPos(1, 5)
  centerText("Field Active For " ..count.. " Seconds")
  sleep(0.5)
  count = count - 1
  if count < 0 then
    redstone.setOutput("right", false) --Change "right" to the OUTPUT side.
    Mon.clear()
    check()
  end
end
end

function check()
 while true do
   if redstone.getInput("left") then defence() end  -- Change "left" to the INPUT side.
      os.pullEvent("redstone")
   end
end

check()
Edited on 19 March 2014 - 11:07 PM