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

Loopin's Programs

Started by Loopin, 27 March 2012 - 01:33 AM
Loopin #1
Posted 27 March 2012 - 03:33 AM
Hey guys, i'll put my programs for CC here, i am a begginer, and it will help if you guys say to me if a thing is wrong.

Programs
SpoilerMy Login/Protection Program.
Spoiler





os.pullEvent=os.pullEventRaw
l1="Change"
l2="Change"
s1="change"
s2="change"
tries=5
id=os.getComputerID()



function goodLogin()  
print("Correct Password!")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("You are logged in computer "..id..".")
end

function badLogin()

print("No More Tries!")
sleep(2)
os.reboot()

end

function togo()
term.clear()
term.setCursorPos(1,1)

print("Tries Left:", tries)
print("Put Your Login.")
write("Login:")
lo=read()

write("Password : ")

pa=read("*")

if lo == l1 and pa == s1 then  
goodLogin()

elseif lo == l2 and pa == s2 then  
goodLogin()

elseif tries==0 then
badLogin()
else
tries=tries-1
term.clear()
term.setCursorPos(1,1)
togo()
end
end
togo()

A Instant Messager
Spoilerlocal name=" "
local y=3
local id=os.getComputerID()


local function draw()
print("Logged as:"..name)
print("——————————")
end

local function exit()
term.clear()
term.setCursorPos(7,7)
print("Disconnected")
ex=name.." Disconnected"
rednet.broadcast(ex)
sleep(3)
os.reboot()
end

local function clear()
term.clear()
term.setCursorPos(1,1)
end


local function check()
while true do
local e, p1, p2, p3= os.pullEvent()
if e=="rednet_message" then
y=y+1
print(p2)
elseif e=="key" and p1==28 then
term.setCursorPos(1,16)
print("Message:")
m=read()
if m=="/exit" then
exit()
elseif y>=15 then
y=3
term.clear()
term.setCursorPos(1,1)
draw()
print(mb)
sleep(1)
check()
else
local mb=name..":"..m
term.setCursorPos(1,16)
term.clearLine()
term.setCursorPos(1,17)
term.clearLine()
term.setCursorPos(1,y)
rednet.broadcast(mb)
term.clearLine()
print(name,":",m)
y=y+1
check()
end
end
end
end


local function init()
clear()
rednet.open("left")
rednet.open("right")
rednet.open("top")
rednet.open("bottom")
rednet.open("back")
print("Choose a Name.")
write("Name:")
name=read()
clear()
draw()
check()
end


init()
Turtle Wireless Movement
Let you control the Turtle by Wireless.

Turtle
Spoilerlocal v=0.1
local function clear()
term.clear()
term.setCursorPos(1,1)
end

local currentslot=1

local function receive()
if not turtle then
print("This is for turtle.")
return
end
turtle.select(1)
while true do
local e,p1,p2,p3=os.pullEvent()
if e=="rednet_message" and p2=="@W" then
turtle.forward()
print("Front")
elseif e=="rednet_message" and p2=="@S" then
turtle.back()
print("Back")
elseif e=="rednet_message" and p2=="@D" then
turtle.turnRight()
print("Right")
elseif e=="rednet_message" and p2=="@A" then
turtle.turnLeft()
print("Left")
elseif e=="rednet_message" and p2=="@U" then
turtle.up()
print("Up")
elseif e=="rednet_message" and p2=="@CTR" then
turtle.down()
print("Down")
elseif e=="rednet_message" and p2=="@DIG" then
turtle.dig()
print("Dig")
elseif e=="rednet_message" and p2=="@DIGD" then
turtle.digDown()
print("Dig Down")
elseif e=="rednet_message" and p2=="@DIGU" then
turtle.digUp()
print("Dig up")
elseif e=="rednet_message" and p2=="@P" then
turtle.place(currentslot)
print("Place")
elseif e=="rednet_message" and p2=="@1" then
turtle.select( 1 )
currentslot=1
elseif e=="rednet_message" and p2=="@2" then
turtle.select( 2 )
currentslot=2
elseif e=="rednet_message" and p2=="@3" then
turtle.select( 3 )
currentslot=3
elseif e=="rednet_message" and p2=="@4" then
turtle.select( 4 )
currentslot=4
elseif e=="rednet_message" and p2=="@5" then
turtle.select( 5 )
currentslot=5
elseif e=="rednet_message" and p2=="@6" then
turtle.select( 6 )
currentslot=6
elseif e=="rednet_message" and p2=="@7" then
turtle.select( 7 )
currentslot=7
elseif e=="rednet_message" and p2=="@8" then
turtle.select( 8 )
currentslot=8
elseif e=="rednet_message" and p2=="@9" then
turtle.select( 9 )
currentslot=9
end
end
end
rednet.open("right")
clear()
print("Current Ver:",v)
print("Receiving Commands.")
receive()

Computer
Spoilerlocal v=0.1
local function clear()
term.clear()
term.setCursorPos(1,1)
end


local function initializate()
rednet.open("right")
rednet.open("top")
rednet.open("back")
rednet.open("bottom")
rednet.open("left")
clear()
while true do
clear()
print("W-front, S-back, D-right ,A-Left,P-Place,Enter-Dig,Down-Dig down, Up-Dig Up, 1 to 9 numbers, select item slot,Left Control-Down,Space- Up")
local e,p1,p2,p3=os.pullEvent()
if e=="key" and p1==17 then
rednet.broadcast("@W")
clear()
print("Front")
elseif e=="key" and p1==31 then
rednet.broadcast("@S")
clear()
print("Back")
elseif e=="key" and p1==32 then
rednet.broadcast("@D")
clear()
print("Right")
elseif e=="key" and p1==30 then
rednet.broadcast("@A")
clear()
print("Left")
elseif e=="key" and p1==57 then
rednet.broadcast("@U")
elseif e=="key" and p1==29 then
rednet.broadcast("@CTR")
elseif e=="key" and p1==28 then
rednet.broadcast("@DIG")
elseif e=="key" and p1==200 then
rednet.broadcast("@DIGU")
elseif e=="key" and p1==208 then
rednet.broadcast("@DIGD")
elseif e=="key" and p1==25 then
rednet.broadcast("@P")
elseif e=="key" and p1==2 then
rednet.broadcast("@1")
elseif e=="key" and p1==3 then
rednet.broadcast("@2")
elseif e=="key" and p1==4 then
rednet.broadcast("@3")
elseif e=="key" and p1==5 then
rednet.broadcast("@4")
elseif e=="key" and p1==6 then
rednet.broadcast("@5")
elseif e=="key" and p1==7 then
rednet.broadcast("@6")
elseif e=="key" and p1==8 then
rednet.broadcast("@7")
elseif e=="key" and p1==9 then
rednet.broadcast("@8")
elseif e=="key" and p1==10 then
rednet.broadcast("@9")
end
end
end

clear()
if turtle then
print("This is for Computer!")
return
end
print("Turtle Wirelles Movement Program!")
print("Ver:"..v)
sleep(4)
initializate()


API
SpoilerNone.

To do List:
Make another Program.
Make An API.
If has some errors please, tell me.
Credits:Virtualayu
Wolvan #2
Posted 27 March 2012 - 08:19 AM
Is this terminate safe?
Loopin #3
Posted 27 March 2012 - 10:59 AM
Yes.
Wolvan #4
Posted 27 March 2012 - 12:36 PM
Nice for a beginner :o/>/> If yu need any help just ask
Loopin #5
Posted 27 March 2012 - 04:41 PM
Nice for a beginner :o/>/> If yu need any help just ask
Thanks! :o/>/>
virtualayu #6
Posted 27 March 2012 - 09:18 PM
Nice program but i think it can be optimized,

Look at my ideas :
Spoilerl1="Change"–First Login
l2="Change"–Second Login
s1="Change"–First Password
s2="Change"–Second Password
os.pullEvent=os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("Computer Protection System.")
print("Initializing")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Computer Protection System.")
print("Initialized!")
sleep(3)
term.clear()
term.setCursorPos(1,1)
print("Put Your Login.")
write("Login:")
lo=read()
if lo==l1 then // change for if lo == l1 or lo == l2 then (that will combine the two "if" in one)
print("Correct Login!")
sleep(2)
term.clear()
term.setCursorPos(1,1)
elseif lo==l2 then —–—delete from here (this is no more usefull)
print("Correct Login!")
sleep(2)
term.clear()
term.setCursorPos(1,1) ——- to here
else
print("Incorrect Login.")
sleep(2)
os.shutdown()
end
print("Now Put Your Password.")
write("Password:")
pa=read("*")
if pa==s1 then —— here you have the same thing… in your code you don't make any difference between the two logins so it's useless to make a difference between the two password… so you can
do the same of above : if pa == s1 or pa == s2 then … and delete what is useless.
print("Correct Password!.")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem..")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initialized!")
term.clear()
term.setCursorPos(1,1)
print("+=============+")
print("+ Terminal 1 +")
print("+=============+")
elseif pa==s2 then
print("Correct Password!.")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem..")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initialized!")
term.clear()
term.setCursorPos(1,1)
print("+=============+")
print("+ Terminal 1 +")
print("+=============+")
else
print("Incorrect Password.")
sleep(2)
os.shutdown()
end

If you want to make a difference between all logins and passwords tell me i have some ideas ^^
Tell me if a made some mistakes
and escuse me for my english, i'm french ^^
Loopin #7
Posted 27 March 2012 - 10:53 PM
Nice program but i think it can be optimized,

Look at my ideas :
Spoilerl1="Change"–First Login
l2="Change"–Second Login
s1="Change"–First Password
s2="Change"–Second Password
os.pullEvent=os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("Computer Protection System.")
print("Initializing")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Computer Protection System.")
print("Initialized!")
sleep(3)
term.clear()
term.setCursorPos(1,1)
print("Put Your Login.")
write("Login:")
lo=read()
if lo==l1 then // change for if lo == l1 or lo == l2 then (that will combine the two "if" in one)
print("Correct Login!")
sleep(2)
term.clear()
term.setCursorPos(1,1)
elseif lo==l2 then —–—delete from here (this is no more usefull)
print("Correct Login!")
sleep(2)
term.clear()
term.setCursorPos(1,1) ——- to here
else
print("Incorrect Login.")
sleep(2)
os.shutdown()
end
print("Now Put Your Password.")
write("Password:")
pa=read("*")
if pa==s1 then —— here you have the same thing… in your code you don't make any difference between the two logins so it's useless to make a difference between the two password… so you can
do the same of above : if pa == s1 or pa == s2 then … and delete what is useless.
print("Correct Password!.")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem..")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initialized!")
term.clear()
term.setCursorPos(1,1)
print("+=============+")
print("+ Terminal 1 +")
print("+=============+")
elseif pa==s2 then
print("Correct Password!.")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initializing Sistem..")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Initialized!")
term.clear()
term.setCursorPos(1,1)
print("+=============+")
print("+ Terminal 1 +")
print("+=============+")
else
print("Incorrect Password.")
sleep(2)
os.shutdown()
end

If you want to make a difference between all logins and passwords tell me i have some ideas ^^
Tell me if a made some mistakes
and escuse me for my english, i'm french ^^
Thanks For the ideas!, i'm not english too xD.
Loopin #8
Posted 30 March 2012 - 06:54 PM
Forget the email and API.
Loopin #9
Posted 10 May 2012 - 07:25 PM
New program! check out.
Loopin #10
Posted 15 May 2012 - 09:46 PM
Turtle Control program added!
Learning_inpaired #11
Posted 17 May 2012 - 04:32 AM
im a noob when it comes to this stuff kind of….
My question is do i type the program name "WoodzyIM"
then enter or make some kind of "fake" login info?
make u can add like a help -enter- menu of some kind
this would be amazing for a small town im makeing

ok i put all that code in for the IM program u made and i have an error
bios:206: [string "Woodim"]:21: '=' expected

how do i fix this im very noob but i do think that the error is on line 21, right?
Loopin #12
Posted 17 May 2012 - 06:53 PM
No errors in IM xP, you put a modem?
if yes, just copy again.
Learning_inpaired #13
Posted 18 May 2012 - 12:19 AM
No errors in IM xP, you put a modem?
if yes, just copy again.
like i sad im veery noob at this i looked over the code on the PC file called "Woodim"
and everything looks good i cant seem to get it i did have a moden on two pc's so idk
maby u can log in the server and look it over
Loopin #14
Posted 18 May 2012 - 08:35 PM
i've tested, and it works fine here, can u pic and post here?