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

Kind of a cinema program(Where is my mistake?)

Started by epiccodernamez, 14 August 2012 - 03:39 PM
epiccodernamez #1
Posted 14 August 2012 - 05:39 PM
I am currently working on this code for the cinema on my tekkit server–>

Startup:

shell.run("cinema")
The cinema program itself:

if redstone.getInput("right") == true then
monitor back secret/alongtimeago
elseif
os.reboot()
end
There might be more than 1 mistakes.
Thanks. :P/>/>)
Cranium #2
Posted 14 August 2012 - 05:42 PM

if redstone.getInput("right") == true then
shell.run("monitor", "back", "secret/alongtimeago") --need to use shell.run within the program
else --you didnt specify anything for the elseif, so it should be an else
os.reboot()
end

Corrected code here, with notes.
epiccodernamez #3
Posted 14 August 2012 - 06:12 PM
I figured out a better code so that when i flick it on it starts and when i flick the lever off it immediately stops.


while redstone.getInput("right") == true do
shell.run("monitor", "back", "secret/alongtimeago")
if redstone.getInput("right") == false then
sleep(5)
os.reboot()

I get the following error:


bios:206: [string "cinema"]:6: 'end' expected (to close 'while' at line 1)
Cranium #4
Posted 14 August 2012 - 06:14 PM
you need to close your statements with ends. In this case, you need two of them at the end. For every while/if/for, you need an end. For if's, if you use an elseif, you only need one end.
Pharap #5
Posted 14 August 2012 - 06:44 PM

while redstone.getInput("right") == true do
shell.run("monitor", "back", "secret/alongtimeago")
if redstone.getInput("right") == false then
sleep(5)
os.reboot()

you need to close your statements with ends. In this case, you need two of them at the end. For every while/if/for, you need an end. For if's, if you use an elseif, you only need one end.
so you need to change it to this:

while redstone.getInput("right") == true do
shell.run("monitor", "back", "secret/alongtimeago")
if redstone.getInput("right") == false then
sleep(5)
os.reboot()
end
end
But technically you don't need to reboot the whole system, so try this if you're feeling adventurous:


while true do
os.pullEvent("redstone")
if redstone.getInput("right") == true then
shell.run("monitor", "back", "secret/alongtimeago")
if redstone.getInput("right") == false then
sleep(5)
if shell.GetRunningProgram() ~= "startup" then
shell.exit() --exits the running program
end
local mon = peripheral.wrap("back") -- gets a reference to the monitor that can be used to control it
mon.clear() -- clears the monitor
end
end
BigSHinyToys #6
Posted 14 August 2012 - 07:05 PM
This program will do it All the above are forgetting that shell.run() stops the program there until it finishes. This program bellow is tested and works

put Redstone on right side and it will play when you stop the Redstone power it will end.
[edit] Fixed a big bug this is ver 3 [/edit]
Spoiler

local sSide = "front"
local sMonitor = "right"
local function input()
    while true do
	    os.pullEvent("redstone")
	    if not redstone.getInput(sSide) then
		    break
	    end
    end
end
local function play()
    shell.run("secret/alongtimeago")
end
while true do
    term.clear()
    term.setCursorPos(1,1)
    print("Flick "..sSide.." switch to play")
    mon = peripheral.wrap(sMonitor)
    term.redirect(mon)
    while true do
	    os.pullEvent("redstone")
	    if redstone.getInput(sSide) then
		    break
	    end
    end
    parallel.waitForAny(input,play)
    term.clear()
    term.setCursorPos(1,1)
    term.restore()
end
Pharap #7
Posted 14 August 2012 - 07:58 PM
This program will do it All the above are forgetting that shell.run() stops the program there until it finishes. This program bellow is tested and works

put Redstone on right side and it will play when you stop the Redstone power it will end.
[edit] Fixed a big bug this is ver 3 [/edit]
Spoiler

local sSide = "front"
local sMonitor = "right"
local function input()
	while true do
		os.pullEvent("redstone")
		if not redstone.getInput(sSide) then
			break
		end
	end
end
local function play()
	shell.run("secret/alongtimeago")
end
while true do
	term.clear()
	term.setCursorPos(1,1)
	print("Flick "..sSide.." switch to play")
	mon = peripheral.wrap(sMonitor)
	term.redirect(mon)
	while true do
		os.pullEvent("redstone")
		if redstone.getInput(sSide) then
			break
		end
	end
	parallel.waitForAny(input,play)
	term.clear()
	term.setCursorPos(1,1)
	term.restore()
end

I did think it might do that, but I couldn't think of a work-around, so I let it be.