HomeКомпьютерные игрыRelated VideosMore From: FunshineX

ComputerCraft Tutorials for Minecraft 1.6 - Part 4 : Basic but Practical Programs

266 ratings | 29487 views
In this episode we'll start writing a basic but very useful program. Topics covered are redstone, menus, password input, loops, startup, and termination prevention. Code: HouseControl: http://pastebin.com/TVWcHvb4 startup: http://pastebin.com/J0Fj7tYQ Minecraft: https://minecraft.net Forge: http://www.minecraftforge.net/forum/ ComputerCraft: http://www.computercraft.info/
Html code for embedding videos on your blog
Text Comments (113)
WizzyBotCraft (4 months ago)
LUA function printCentered(y,s) local x = math.floor((w - string.len(s)) /2 term.setCursorPos(x,y) term.clearLine() term.write(s) end function passCheck() password = “42” fails = 0 term.clear() term.setCursorPos(1, 1) term.write(“Password: “) input = Read(‘*’) if input == password then fails = 0 return true else fails = fails + 1 return false end local nOption = 1 term.clear() local function drawBrackets() printCentered(mat.floor(h/2) - 2, ((nOption == 1) and “[ Open Door ]”) or “Open Door”) printCentered(mat.floor(h/2) - 1, ((nOption == 2) and “[ Close Door ]”) or “Close Door”) printCentered(mat.floor(h/2) + 0, ((nOption == 3) and “[ Lights On ]”) or “Lights On”) printCentered(mat.floor(h/2) + 1, ((nOption == 4) and “[ Lights Off ]”) or “Lights Off”) end while true do local e,p = os.pullEvent if e == “key” then local key = p if key == 200 then if nOption > 1 then nOption = nOption - 1 drawBrackets() end elseif key == 208 then if nOption < 4 then nOption = nOption + 1 drawBrackets() end elseif key == 28 then break end end term.clear() if nOption == 1 then if passCheck == true then rs.setOutput(“bottom”, true) else term.clear() term.setCursorPos(1, 1) print(“Wrong Password!”) end if fails < 4 then sleep(2) else print(“Spam Detected! Try again in 10 seconds...”) sleep(10) end elseif nOption == 2 then rs.setOutput(“bottom”, false) elseif nOption == 3 then rs.setOutput(“back”, true) elseif nOption == 4 then rs.setOutput(“back”, false) end end
Tony Flamingo (1 year ago)
I'm typing in rs.setOutput ("bottom".true ) and it keeps saying lua:39: [string "lua"]:1: ')' expected what do I do?
OrangeC7 (1 year ago)
How can I check the length of a string, if I can?
Caffine Molecule (1 year ago)
Maybe len(<Str>)? That's what it is in Python.
Party Channel (2 years ago)
Suuuuuper nice vid. It helpt me a lot
Adam Kleinberg (2 years ago)
You can ward wood.
Tristan James (2 years ago)
nice password, 42 is the answer to all
Memester van Malsen (2 years ago)
help if i do: if checkpassword() == true then Coding here>> else Codeing here>> It doesnt wat to go to those pages but it alsodoesnt give me an error o dont know why i have set the password and everything. What do i need to do?
Asami Morning (2 years ago)
of all things you know how to program a computer yet not know redstone sad
Memester van Malsen (2 years ago)
+littleindian maiden he learns to much in the computers so he doesnt have time for those things
seenboi (3 years ago)
It keeps saying a the nil thing
Asami Morning (2 years ago)
+Sean Doster means some unknown value givin in the program
Bigsand Productions (3 years ago)
I have been programming lua on the pc (not computercraft) and i cant think of anywhere else to ask, so i ask here: What is <EOF> ?i get an error on literly every program i write stating that <EOF> is expected near elseif of else. Please help
Bigsand Productions (3 years ago)
+FunshineX thx
FunshineX (3 years ago)
+Mr Bigsand EOF means "end of file" and means the interpreter reached the end of the file before reading some tag that it expected. Most often you just forgot an "end" for each "if"
jovan zavier (3 years ago)
it says HouseControl:2: attempt to call nil what do i do?!?!
jovan zavier (3 years ago)
8:04 in the video right there it says it
I get a error on the code at http://youtu.be/J23q6iAguPU?t=7m7s ("bios:366:[string "test"]:21 'end' expected (to close 'while' at line 4")
Cowslayer7890 (3 years ago)
You need another "end" at the end
Tyler Toole (3 years ago)
numFails... It sounds like a particularly horrid insult. :p
xBoloRei (3 years ago)
i did the exact same thing as you did but here it said:  controlocasa:4: attempt to call nil can you help me?
Thomasynthesis (3 years ago)
+shanchan hd  *Happy to help.*
Thomasynthesis (3 years ago)
+shanchan hd You need to end the while with "end".
xBoloRei (3 years ago)
Thx a lot
FunshineX (3 years ago)
You've got something wrong on line 4...check it again. 
Lila_Pickle (3 years ago)
I have redone the coding twice and I have now got the following error message when I go to run the program: bios:366:[string "drctrl"]:16:unexpected symbol I am not sure what I have done wrong, I have checked and rechecked and done everything as done in the tutorial. Any help would be greatly appreciated.
akpwgp (3 years ago)
I need help i got rid of the break and now it wont let me do anything else
The Odd Critic (3 years ago)
Lord... This brings me back to Javascript... Javascript was so hard for me :/
9000dgo (3 years ago)
For the respond activating thing it said lua:36 [string "lua"]: 1: ')' expected
cody lanz (2 years ago)
Try this redstone.setOutput("bottom", true)
9000dgo (3 years ago)
I mean redstone
Some Guy (3 years ago)
Can you help when I try and open my door it just goes straight to saying invalid password not letting me type the password here is the code password = "2845" function checkPassword()  term.clear()  term.setCursorPos(1,1) print ("Enter the password") input = io.read()   if input == password then return true else return false end end while true do term.clear() term.setCursorPos(1,1) print ("What do you want to do?") print ("1=Open Door") print ("2=Close Door") print ("Q=Quit") input = io.read() if input == "1" then if checkPassword == true then   rs.setOutput ("right",true)   else   term.clear()   term.setCursorPos(1,1)   print ("Invalid Password")   sleep(2)   end   elseif input == "2" then  rs.setOutput ("right",false) elseif input == "Q" then break else  print ("Invalid entry")  end end
Some Guy (3 years ago)
+FunshineX Thanks :)
FunshineX (3 years ago)
you're not calling the function correctly, use this: if checkPassword() == true then
JayUPL (3 years ago)
check out this website to test you code. (If you don't have the mod yet) http://www.lua.org/cgi-bin/demo
Extinct Hart (4 years ago)
It says bios:366: [string "security"]: '=' expected (Btw: security is the name of my program) +Funshinex
Gavin :D (4 years ago)
Help I cant do startup beacause when I start my computer it says startup:1: attempt to call nil
Nep Nep (4 years ago)
i did the EXACT same thing as you did but here it said:  lua:36: [string "lua"]:1: ')' expected and then nothing happened well, something happened, my brother got outside of that house and saw creeprs, got scared, runned in my house with the creepers and they exploded and then my computer dropped and got destroyed by another creeper D:< and all the redstone and the monitors too 
Diesel (4 years ago)
keeping getting HouseControl:1: attempt to index ? (a nil value) code matches yours exactly, although I use 1.5 for FTB monster
Diesel (4 years ago)
+FunshineX thanks for getting back promptly. Much appreciated. as stated I'm using the latest FTB Monster but w/ computer craft v1.5. using the short hand term. instead of terminal how I had it seems to have worked. 
FunshineX (4 years ago)
Post line 1
Gamecraft (4 years ago)
I got a problem, the code works, but the redstone will not be active or deactive before a block update next to the redstone. This means I need to place a block or remove a block befor it's updated.
Skulleaus Latin (4 years ago)
Are you able to make a pet turtle that would kill mobs/players that you attack? And it will also follow you?
FunshineX (4 years ago)
Nope turtles cannot do that
Vlad Barcelo (4 years ago)
1=Open Door 2=Get on the Floor 3=Everybody do the Dinosaur
jbsilverdragons (4 years ago)
You should of had a powered torch under the door. Anyone can walk up and place a torch down to open it. If the torch under is powered you can "open" it by sending the redstone signal to the torch. What I mean by "open" is the door is always open it is just turned so it blocks you when it is open and lets you through when it is closed. Thus even if they put a redstone torch down they cannot go through because the door is already open.
Logan Cottreau (4 years ago)
hello i have typed exact thing but with 8 controls with 4 sides using redstone and says: bios:337: [string "control"] : 75 : 'end' expected (to close 'while' at line 23). You told me to add an end but where would i put it?
Logan Graham (4 years ago)
you are missing and end somewere go to line 23 and find out were it is missing
Andoxico (4 years ago)
Where you want the loop to stop
Tvvsgaming (4 years ago)
dosent work!
jason vorhees (4 years ago)
it works for me
Michael Dahlin-Yates (4 years ago)
Ah, I see
hans (4 years ago)
+michael dahlin-yates It is, but a lot of people just say "parenthese" for singular which is weird.
Michael Dahlin-Yates (4 years ago)
+ikbinhans I thought parenthesis was both plural and singular
hans (4 years ago)
+FunshineX I love that you know the singular form of parentheses :P One of the few, seemingly.
TheWhiteShadow (4 years ago)
ERROR bios:338: [string "HouseControl"]:48:  '<eof>' expected help :(
TheWhiteShadow (4 years ago)
no help more needed ;D
Andoxico (4 years ago)
what's line 48?
BROx Prodigy (4 years ago)
HELP PLEASE! im getting a error repeaddly saying  bios:339: [string "HouseControl"]:5: '=' expected  i dont know how to fix this ive whent through all my lines.
FunshineX (4 years ago)
For starters, post line 5 :)
ideacreeper (4 years ago)
please make more, on the next 1.7 version, please?
Jovian Tan (4 years ago)
U scared me at the start lol
Mathias Danielsen (4 years ago)
Thank you i know lua coding but i did not know how i could use cc and stuffs practiacal
Max Miller (4 years ago)
These are great tutorials, thanks so much!
Logan Graham (4 years ago)
wtf why wont this text work!
Logan Graham (4 years ago)
i mean while true do input = io.read() if input == "password here" then break else end end
Logan Graham (4 years ago)
well that would be easy edit start up type in while true do input = io.read() if input == "password here" then break else end end
Farriba Steelhand (4 years ago)
How about a password protected PC startup?
Caspar Stanley (4 years ago)
No loop to break?
Ethan Hein (4 years ago)
my problem relates to jtsmasterf3
Eildriz Niño Guanzon (4 years ago)
It's Said To Me That ... "error mounting lua/rom" ? What I'm gonna do?
FunshineX (4 years ago)
check line 1 of both the startup program and the other program, paste them here
FunshineX (4 years ago)
see how it says ")" expected. It means you have a typo and are missing a )
weckar (4 years ago)
Program I'd be interested in: Door program with MULTIPLE passwords that (secretly) keeps a log of WHEN certain passwords have been used (based on time and day). That would make it easier to see who stole, griefed, etc.
Panu (4 years ago)
hi funshine.I would like to know,if i can make a floppy disk that would have a code. So if you would place that floppy in a computer you could skip the password? and if that is possible can you make a tutorial of that
Wolf Leader (4 years ago)
Could you do one for turtles.
Wolf Leader (4 years ago)
Could you do one for turtles.
FunshineX (4 years ago)
All code is tested and works in 1.6.2. You'll find a link in the description.
TheLoneMinecraftian (4 years ago)
The Failure Thing Dosent Work!! Please Post The Failure Part Only!
Nevexo (4 years ago)
or.. u could place a disk drive next to it to overright the boot dir
KraphtersUniverse (4 years ago)
for some reason the Ctrl+r, Ctrl+t, ect... won't work for me. How do i fix this??
Whiptail84 (4 years ago)
Love your tutorials and even if I know most of it, I always learn from you. Are you planning to make a tutorial for reading/writing to files?
Whiptail84 (4 years ago)
And if you do os.pullEvent("redstone"), the event will ONLY react to redstone events. ;)
Matthew Vincent (4 years ago)
Great! Also it would be easier with the one option for the door, and lights. Also you could save th current state of them.into a file, then read that when the computer is opened. You could also save the number of tries for the password, so if someone were to try and use CTRL + R then it would restart the timer to 30 seconds. Also when you had the "Q= Quit" many people would just put "q" and you could make it so the computer put all inputs to a lowercase, I've done that before, but I've forgotten
FunshineX (4 years ago)
ah great trick!
FunshineX (4 years ago)
You'd need a program running a loop that calls os.pullEvent() and check if the event is redstone.
8bitslime (4 years ago)
lets say the door var would be door = true/false and the code to 'switch' it would be door = not door rs.setOutput('side', door) not is the opposite of the value of a boolean variable. Hope this helped!
Titan Empoly (4 years ago)
You don't have to worry at all!If all of the videos in this series will be like those first ones,it's worth waiting!
Titan Empoly (4 years ago)
Ron,is it possible for a computer/turtle to get redstone input?For example,I want my turtle to work just when it gets a redstone signal,is it possible for me to do it?
Wymmie (4 years ago)
you dont have to go to text a floppy disk with startup named empty program is enough
fuck (4 years ago)
Ah yes, don't worry. We can wait :D. Lol, vanilla derps
FunshineX (4 years ago)
Trying to get them up as fast I can. I want to make sure the quality is top notch since my first series had a lot of audio issues, vanilla derps, and just plain bad code :)
Thraix (4 years ago)
What he did was nested a if statement -> he put an if statement inside a if statement. The first thing he checked was if the number is equal to "1". And if it is it continues to the next if statement which checked the password. If it isn't equal to "1" then it doesn't run the other if statement inside the first one. Hope it made sense. Otherwise just tell me where I lost you :P
FunshineX (4 years ago)
when I do all the if/else commands for each input 1-4, I only call the checkPassword function if the input=="1"
FunshineX (4 years ago)
Yes I could have just done one command called Toggle. I'd have to store the current redstone state, and just set it to the opposite value
Thraix (4 years ago)
if rs.getOutput("Side to test") then rs.setOutput("Side to test",false) else rs.setOutput("Side to test",true) end hope I did that right. haven't tested it.
Creator2001s (4 years ago)
Hey Ron, I'm a newbie at programming and one question I have is during 13:00 how does the computer know to check the password only if the number "1" was the input?
MrSoccerboy5411 (4 years ago)
awesome intro to CC programming! I can't wait for turtles!!!
karelmikie3 (4 years ago)
same here
Amado Garcia (4 years ago)
I like computers but I would like some information on turtles and could you try to slow down a bit I only get stuff you type/say like 15 times thx =)
fuck (4 years ago)
Same, I learnt most of what I know from Ron, and am patiently waiting for the harder programs
Lebotats (4 years ago)
pretty cool tutorial... nothing i didnt know but very interesting... looking forward to the more advanced subjects!
Stefan (4 years ago)
first

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.