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

My very first Computercraft program!

Started by natenat3p, 12 June 2013 - 07:26 AM
natenat3p #1
Posted 12 June 2013 - 09:26 AM
This is a simple program that I wrote by using a tutorial video. It simply asks you to enter a password. The first time, you have to enter "pass" (without the "") and then if you type it wrong, it will keep looking for you to type "pass". Then once you get that right, it will ask you to type in a second password which is "password". Once you have typed in both passwords correctly, you can have that go into another program or run whatever you want it to. This is just for input of a password.



function getPass(checkPass)
  local pass = ""

  term.write("Please enter the password:")
  pass = read()
  if pass ~= checkPass then
	print("wrong Password!!")
  return false
	else
	print("Correct Password!")
	  return true
  end
end

print("Starting Program!")
  while not getPass("pass") do
	print("Please Try Again")
  end
while not getPass("password") do
  print(
  "No really, Try again!")
end
jesusthekiller #2
Posted 12 June 2013 - 11:14 AM

os.pullEvent = os.pullEventRaw
local pass
repeat
  write("Password: ")
  pass = read("x")
  term.clear()
  term.setCursorPos(1,1)
until pass == "pass" -- Set password here
print("Welcome!")

A bit shorter :)/>
natenat3p #3
Posted 12 June 2013 - 11:28 AM
Thank you kind sir. XD
jesusthekiller #4
Posted 12 June 2013 - 11:29 AM
Np :ph34r:/>
natenat3p #5
Posted 12 June 2013 - 11:29 AM
I haven't heard of pullevent yet. what is that for?
jesusthekiller #6
Posted 12 June 2013 - 11:31 AM
This line prevents CTRL+T

os.pullEvent pulls an event from queue <– Click for wiki

It's very powerful thing in CC, as powerful as i.e. parallel :)/>
M4sh3dP0t4t03 #7
Posted 12 June 2013 - 11:40 AM
Os.pullEvent() basicly waits for an event like a change in redstone or a mouse click(there is a list of all events on the wiki page) and returns some stuff about it.
nutcase84 #8
Posted 12 June 2013 - 12:31 PM
Wow. Nice first program. This was mine:


print "Hello World!

:D/>
natenat3p #9
Posted 13 June 2013 - 07:14 AM
Wow. Nice first program. This was mine:


print "Hello World!

:D/>

Haha nice. I watched a bunch of videos before I started. XD
jesusthekiller #10
Posted 13 June 2013 - 08:12 AM
I used in-game tutorial :)/>

Learned more via tutorials section tho, go check it out :)/>
TheOddByte #11
Posted 14 June 2013 - 03:03 PM
I used in-game tutorial :)/>/>

Learned more via tutorials section tho, go check it out :)/>/>
I tested my way forward then i read other peoples codes to learn from them, And I have found out that I learn best from reading other peoples codes :)/>
Dave-ee Jones #12
Posted 15 June 2013 - 07:06 AM
Wow. Nice first program. This was mine:


print "Hello World!

:D/>
Even then you got it wrong :P/>
jesusthekiller #13
Posted 15 June 2013 - 12:35 PM
It's correct…
In Lua you don't have to do brackets if only one argument is passed.

MudkipTheEpic #14
Posted 15 June 2013 - 01:34 PM
He missed the last (").
jesusthekiller #15
Posted 15 June 2013 - 01:36 PM
Oh <_</>
Geforce Fan #16
Posted 17 June 2013 - 09:47 PM
Not bad for a very first program. Mine was something like print("Testing, one two three")
jesusthekiller #17
Posted 18 June 2013 - 02:58 AM
No necromancy allowed :-)