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

Need someone to write a program

Started by Sep, 29 December 2015 - 03:12 PM
Sep #1
Posted 29 December 2015 - 04:12 PM
Well, the title should say what the topic is.
I have played around ComputerCraft and Lua a little and as embarassing as it is, I'm too bad to write a simple program. So if anyone would be sweet and help me out here, I'd much appreciate it :)/>
So here the data one might need:
Monitor standing to the left
Redstone Input should come frome the bottom
Redstone Output should go out at the top
The program should check for Redstone Input and as long as there is none, the monitor should show "Laboratory inactive" and as soon as I put a signal in, the monitor text should be changed to "Laboratory active" and stay like that until the redstone signal gets put out. Additionally when the laboratory is "active", there should be an output to the top, which gets deactivated when the laboratory is "inactive"

I know, that is like the most basic function you can do but I'm unable to do that. Well, I hope there is someone who is willing to put up with my stupidity

Greetings to the players - Sep
Lyqyd #2
Posted 29 December 2015 - 07:43 PM
Moved to General. Ask a Pro is for help creating a program, not for program requests.
Lupus590 #3
Posted 29 December 2015 - 07:57 PM

local inputSide = "bottom"
local passThroughSide = "top"
local monitorSide = "left"
local onMessage = "Laboratory active"
local offmessage = "Laboratory inactive"

local mon = peripheral.wrap(monitorSide)
if not mon then
  error("no monitor on expected side: "..monitorSide)
end
local event
mon.setCursorBlink(false)
while true do
  event = { os.pullEvent("redstone")}
  mon.clear()
  mon.setCursorPos(1,1)
  if redstone.getInput(inputSide) then
	mon.write(onMessage)
	redstone.setOutput(passThroughSide,true)
  else
   mon.write(offMessage)
	redstone.setOutput(passThroughSide,false)
  end
end
  

that should do it

edit: bug fix from below
Edited on 30 December 2015 - 02:04 PM
HPWebcamAble #4
Posted 30 December 2015 - 02:53 AM
that should do it

Thought I should mention you need a curly brace on the 'event = {os.pullEvent()}' line, and 'output' needs to be capitalized in the calls to the redstone API.

Other than that looks good.


[member='Sep'], if you want a quick (or in depth) explanation, I'm sure a number of people would be willing to give you one. Just ask ;)/>
Lupus590 #5
Posted 30 December 2015 - 03:05 PM
that should do it

Thought I should mention you need a curly brace on the 'event = {os.pullEvent()}' line, and 'output' needs to be capitalized in the calls to the redstone API.

Thanks
Sep #6
Posted 30 December 2015 - 04:05 PM
First off, thanks for the Answers.

Moved to General. Ask a Pro is for help creating a program, not for program requests.
Sorry, didn't know about that.

And the program works, so thanks to you Lupus500 <3

[member='Sep'], if you want a quick (or in depth) explanation, I'm sure a number of people would be willing to give you one. Just ask ;)/>
I think I do understand how it works. Just was unable to do it myself :/

Thank you for the great help guys
Greetings - Sep