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

Comedic Trap Program, Piston Based Pitfall.

Started by Mr. Fang, 24 September 2012 - 04:31 PM
Mr. Fang #1
Posted 24 September 2012 - 06:31 PM
Really Simple program I'm using in my Batcave, Just make sure you have the computer over a sticky piston and the sticky piston is pushing the block over the hole. Only good if they can't avoid falling into the pit that your supposed to dig beneath the hole.

1.redstone.setOutput("bottom", true)
2.term.clear()
3.term.setCursorPos(1,1)
4.term.print("Name Please.")
5.sleep(5)
6.read()
7.if input = "Batman" then
8.print("No, I'm Batman")
9.redstone.setOutput("bottom", false)
10.sleep(5)
11.redstone.setOutput("bottom", true)
12.print("Goodbye Imposter.") ---I included dialogue like this because i plan to take my friend to the batcave during my let's play.
13.sleep(3)
14.end
15.os.reboot()
16.end

Not Tested yet, but supposed to be fine XD

Pastebin: http://pastebin.com/MV3XDB6t
Noodle #2
Posted 25 September 2012 - 12:44 AM
What if they type 'batman' instead of 'Batman'?
TheOutcast5 #3
Posted 25 September 2012 - 10:52 AM
It might not work
Mr. Fang #4
Posted 25 September 2012 - 11:36 AM
Well, just they're luck if they don't type it correctly on my Single Player World…lol
sjele #5
Posted 25 September 2012 - 08:58 PM

if input = "Batman" then --line 7: You have = instead of ==
Noodle #6
Posted 25 September 2012 - 10:11 PM
It might not work

if input = "Batman" then --line 7: You have = instead of ==

To help with not failing.
redstone.setOutput("bottom", true)
term.clear()
term.setCursorPos(1,1)
term.print("Name Please.")
sleep(5)
input = read() -- Read is not referred to as input because it wasn't established. Now you have input = read()
if string.lower(input) == "batman" then -- Changes input to lowercase
print("No, I'm Batman")
redstone.setOutput("bottom", false)
sleep(5)
redstone.setOutput("bottom", true)
print("Goodbye Imposter.") ---I included dialogue like this because i plan to take my friend to the batcave during my let's play.
sleep(3)
end
os.reboot()
end
Cranium #7
Posted 25 September 2012 - 10:13 PM

redstone.setOutput("bottom", true)
term.clear()
term.setCursorPos(1,1)
term.print("Name Please.") 
local input = read() --still forgot to add input variable.
if string.lower(input) == "batman" then
print("No, I'm Batman")
redstone.setOutput("bottom", false)
sleep(5)
redstone.setOutput("bottom", true)
print("Goodbye Imposter.")
sleep(3)
end
os.reboot()
end

Edited with more fixes.
Noodle #8
Posted 25 September 2012 - 10:17 PM
Edited with more fixes.
There's no reason for the local
if anything you could do
if string.lower(read()) == "batman" then
– code
end
Cranium #9
Posted 25 September 2012 - 10:35 PM
Meh. Still good to make variables local. Good habit to get into. The main problem was that he had just called read(), without being input = read(), so it would not have done anything.
Mr. Fang #10
Posted 27 September 2012 - 03:51 PM
Uh oh…I just realized that this post contains "Malicious Content!"
:P/>/>

Nah JK XD
GopherAtl #11
Posted 27 September 2012 - 04:49 PM
There's no reason for the local
You don't need a specific reason to make a variable local. Every variable should be local unless you have a specific reason for making it global. Rampant and casual use of global variables can lead to some really bizarre-seeming bugs that are tricky to identify.
Cranium #12
Posted 27 September 2012 - 04:52 PM
You don't need a specific reason to make a variable local. Every variable should be local unless you have a specific reason for making it global. Rampant and casual use of global variables can lead to some really bizarre-seeming bugs that are tricky to identify.
Especially in cases like mine that have programs being as long as 2500 lines(working to separate it out), and setting global variables willy-nilly….I have never had a harder time tracking down bugs than switching that ugly code to local variables and functions….