- ComputerCraft | Programmable Computers for Minecraft
- → surferpup's Content
surferpup's Content
There have been 285 items by surferpup (Search limited from 10-February 22)
#165356 Strengthening Password Server Security
Posted by
surferpup
on 19 February 2014 - 01:17 AM
in
Ask a Pro
Edit: NINJA'd by Bomb Bloke (That dude types so dang fast!!!)
#165302 Rednet Issues
Posted by
surferpup
on 18 February 2014 - 04:48 PM
in
Ask a Pro
MKlegoman357, on 18 February 2014 - 01:24 PM, said:
I think you have to have the sleep be at the very least 0.08 seconds for a pulse. If anyone knows better, please advise.
#165300 Terminal Lock Admin Bypass Not Working
Posted by
surferpup
on 18 February 2014 - 04:44 PM
in
Ask a Pro
while true do --Golly, here is my code end
To do so, simply type [code] at the start of your code, and [/code] at the end of your code (note the use of square brackets). This makes it much easier for us to help you resolve your issues (following good indenting rules is also helpful both for you and for us
#165250 Terminal Lock Admin Bypass Not Working
Posted by
surferpup
on 18 February 2014 - 11:00 AM
in
Ask a Pro
term.setTextColour(c_irc)
The correct variable is c_icr not c_irc.
I also agree with what Bomb Bloke and Lyqyd have suggested.
#165230 How to Exit from a While Loop
Posted by
surferpup
on 17 February 2014 - 11:12 PM
in
Tutorials
theoriginalbit, on 17 February 2014 - 11:08 PM, said:
Ahh. I am well-familiar with the work, not with the acronym. I have spent and continue to spend hours scouring the PIL. I also have spent a good amount of time reading posts, answers to posts and tutorials on this site, as well as in the CC Wiki.
My hope is that by referencing an already-existent tutorial, it will help the new member realize the kinds of resources that are available. One can always hope.
#165228 How to Exit from a While Loop
Posted by
surferpup
on 17 February 2014 - 11:02 PM
in
Tutorials
theoriginalbit, on 17 February 2014 - 10:55 PM, said:
Fair enough.
theoriginalbit, on 17 February 2014 - 10:55 PM, said:
I agree that there is always room for improvement and welcome constructive criticism. You will note that I addressed Bomb Bloke's concern, and I am taking the time to address your concerns.
theoriginalbit, on 17 February 2014 - 10:55 PM, said:
I hope the tutorial is informative -- I realize it only addresses a Lua question -- hence the Lua tag. What is a PIL?
theoriginalbit, on 17 February 2014 - 10:55 PM, said:
At least I can just copy/paste the link to this when answering the exiting from while question, rather than constantly having to pump out a new answer.
#165225 How to Exit from a While Loop
Posted by
surferpup
on 17 February 2014 - 10:45 PM
in
Tutorials
theoriginalbit, on 17 February 2014 - 10:24 PM, said:
I apologize. While it did not say specifically on beginning Lua, Lyqyd pointed out: "We've had many new members come through and ask questions, many of them repeats of similar questions that have been asked many times." In reading his post, I interpreted it as a request for a higher quality of tutorials addressing his concern (to lower signal to noise" ratio), as well as on specific topics. There are dozens of questions on Beginning Lua, so I wrote a tutorial on that, explaining the basics of Lua control structures and many of the important key words. In addition to beginning Lua, I have addressed his request for Redstone Basics, and I have almost completed a thorough treatment of Monitor Buttons and Touch Screen Controls.
There is nothing wrong with this tutorial I presented. It answers the question thoroughly, with some thought given to coding practices and an explanation of why things work the way they work. Though I felt it unnecessary, I did include the "return" functionality pointed out by Bomb Bloke. It also answers a question that has come up repeatedly. A search of "exit from while" or "exiting a while" loop will reveal this tutorial, and answer a user question. Since it is properly answering legitimate new member questions, I felt it was appropriate to write.
I am, quite frankly, surprised at your opposition. Has this somehow violated any of the forum guidelines I have read? The tutorial itself is certainly of high enough quality to be posted in the tutorial section, and on a subject which affects many of the new members. If you feel the quality is poor or the tutorial is inappropriate, then feel free to petition to have it removed. It certainly is not written to create controversy, only to help.
#165221 Trying to make a woodchopper program but Im very new to programming
Posted by
surferpup
on 17 February 2014 - 10:04 PM
in
Ask a Pro
#165220 How to Exit from a While Loop
Posted by
surferpup
on 17 February 2014 - 10:01 PM
in
Tutorials
theoriginalbit, on 17 February 2014 - 09:33 PM, said:
Given the number of times I have seen this question come up in the Ask-a-Pro, I thought it warranted. Also, the Ask-a-Pro Renewal Project requested good tutorials on beginning Lua.
Bomb Bloke, on 17 February 2014 - 09:16 PM, said:
True, I mention it in the Lua Basics: Using break to Exit Loops. I just thought that given the way I see the question continue to arise, this pretty much covers it. I will amend to point this out as well.
#165211 Looking for help with a Project.
Posted by
surferpup
on 17 February 2014 - 07:16 PM
in
Ask a Pro
energyCell = peripheral.wrap("left")
local energy = energyCell.getEnergyStored()
print ("Energy Stored: "..tostring(energy))
There are several methods available to you when you peripheral.wrap a Redstone Enrgy Cell. They include:
- setEnergyReceive()
- setEnergySend()
- getEnergyReceive()
- getEnergySend()
- getActivationEnergy()
- getLatency()
- getMinEnergyReceived()
- getMaxEnergyReceived()
- getMaxEnergyStored()
- getEnergyStored()
- getPowerProvider()
If this was helpful to you, please vote my response up.
#165204 Can Someone help me?
Posted by
surferpup
on 17 February 2014 - 06:42 PM
in
Ask a Pro
- indent your code so it makes sense. Your code is unreadable when you don't -- especially for purposes of a tutorial.
- use elseif in your chains of if statements.
- what is your function user.input() -- it does not exist in your code. I assume it is supposed to be a read(). I have changed it to get your code to work.
- line 123 -- spelled Cursor wrong. Should be term.setCursorPos(1,1)
-- Basic Start up Configuration--
local unlock = 1416
local e = "edit"
local side = "left"
--User 1--
local user1 = ""
local pass1 = ""
--User 2--
local user2 = ""
local pass2 = ""
--User 3--
local user3 = ""
local pass3 = ""
--User 4--
local user4 = ""
local user5 = ""
-- Reset Up Configuration --
local setup = false --Set to false to reset system
-- DO NOT EDIT BELOW THIS LINE ---- DO NOT EDIT BELOW THIS LINE ---- DO NOT EDIT BELOW THIS LINE ---- DO NOT EDIT BELOW THIS LINE --
local t = 5
local pass = false
local v = "1.5b"
local run = false
local done = false
local userCheck = ""
local passCheck = ""
local c = ""
if setup == false then
term.clear()
term.setCursorPos(1,1)
print("Welcome To Poptarts Security Door")
term.setCursorPos(1,2)
print("Version:", v)
term.setCursorPos(1,3)
print("Lets Get Started")
sleep(5)
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 1")
term.setCursorPos(1,2)
write("Username: ")
user1 = read()
term.setCursorPos(1,3)
write("Password: ")
pass1 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
sleep(5)
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 2")
term.setCursorPos(1,2)
write("Username: ")
user2 = read()
term.setCursorPos(1,3)
write("Password: ")
pass2 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
sleep(5)
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 3")
term.setCursorPos(1,2)
write("Username: ")
user3 = read()
term.setCursorPos(1,3)
write("Password: ")
pass3 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
-- sleep(5)
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 4")
term.setCursorPos(1,2)
write("Username: ")
user4 = read()
term.setCursorPos(1,3)
write("Password: ")
pass4 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
sleep(5)
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 5")
term.setCursorPos(1,2)
write("Username: ")
user5 = read()
term.setCursorPos(1,3)
write("Password: ")
pass5 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Set-up Complete")
sleep(2)
term.clear()
setup = true
end
while done == false do
term.clear()
term.setCursorPos(1,1)
print("Setup Configured Now Booting")
term.setCursorPos(1,2)
print("Version: ", v)
sleep(2)
term.clear()
while run == false do
redstone.setOutput(side, false)
write("Username: ")
userCheck = read()
term.clear()
if userCheck == user1 then
write("Password: ")
passCheck = read()
term.clear()
if passCheck == pass1 then
print("Access Granted")
sleep(t)
redstone.setOutput(side, true)
term.clear()
end
elseif userCheck == user2 then
write("Password: ")
passCheck = read()
term.clear()
if passCheck == pass2 then
print("Access Granted")
sleep(t)
redstone.setOutput(side, true)
term.clear()
end
elseif userCheck == user3 then
write("Password: ")
passCheck = read()
term.clear()
if passCheck == pass3 then
print("Access Granted")
sleep(t)
redstone.setOutput(side, true)
term.clear()
end
elseif userCheck == user4 then
write("Password: ")
passCheck = read()
term.clear()
if passCheck == pass4 then
print("Access Granted")
sleep(t)
redstone.setOutput(side, true)
term.clear()
end
elseif userCheck == user5 then
write("Password: ")
passCheck = read()
term.clear()
if passCheck == pass5 then
print("Access Granted")
sleep(t)
redstone.setOutput(side, true)
term.clear()
end
elseif userCheck == unlock then
run = true
done = true
elseif userCheck == e then
write("Enter the unlock password:")
usercheck = read()
if userCheck == unlock then
term.clear()
term.setCursorPos(1,1)
print("For user 1-5 use numbers")
term.setCursorPos(1,2)
write("Enter the ID number in which you would like to edit: ")
c = read()
if c == 1 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 1")
term.setCursorPos(1,2)
write("Username: ")
user1 = read()
term.setCursorPos(1,3)
write("Password: ")
pass1 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
elseif c == 2 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 2")
term.setCursorPos(1,2)
write("Username: ")
user2 = read()
term.setCursorPos(1,3)
write("Password: ")
pass2 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(2)
term.clear()
elseif c == 3 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 3")
term.setCursorPos(1,2)
write("Username: ")
user3 = read()
term.setCursorPos(1,3)
write("Password: ")
pass3 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(t)
term.clear()
elseif c == 4 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 4")
term.setCursorPos(1,2)
write("Username: ")
user4 = read()
term.setCursorPos(1,3)
write("Password: ")
pass4 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(t)
term.clear()
elseif c == 5 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the following information for User 5")
term.setCursorPos(1,2)
write("Username: ")
user5 = read()
term.setCursorPos(1,3)
write("Password: ")
pass5 = read()
term.setCursorPos(1,1)
term.clear()
print("Processing...")
sleep(t)
term.clear()
elseif c == "side" then
term.clear()
term.setCursorPos(1,1)
print("Please Enter the output side")
term.setCursorPos(1,2)
write("Side: ")
side = read()
term.setCursorPos(1,3)
print("Testing...")
term.clear()
term.setCursorPos(1,1)
redstone.output(side, true)
sleep(t)
redstone.output(side,false)
elseif c == "Time" then
term.clear()
term.setCursorPos(1,1)
print("Please enter the open time in Seconds")
term.setCursorPos(1,2)
write("Seconds: ")
t = read()
end
end
end
end
end
#165201 Break requiring infinite ends?
Posted by
surferpup
on 17 February 2014 - 05:57 PM
in
Ask a Pro
awsmazinggenius, on 14 February 2014 - 09:09 AM, said:
do break end
CometWolf, on 14 February 2014 - 03:53 PM, said:
Actually, do ... break ... end does not work anywhere, only in loops.
#165198 Trying to make a woodchopper program but Im very new to programming
Posted by
surferpup
on 17 February 2014 - 05:49 PM
in
Ask a Pro
local invCount = {}
for i = 1,11 do
invCount[i] = turtle.getItemCount(i)
end
This will store the number of items in slots 1-11 in your turtle inventory into a table named invCount, such that:
invCount[1] = count of items in slot 1
invCount[2] = count of items in slot 2
... and so on.
If a slot is empty, it will return a 0 for the count.
#165197 Skynet database, Missile Defence System. LOAD, Launch on Detection.
Posted by
surferpup
on 17 February 2014 - 05:17 PM
in
Ask a Pro
burnin_aura, on 16 February 2014 - 12:48 AM, said:
upload the code your using, i might have some errors, now the error lies in the master launch pc where it ignores the signal by not showing indicators of it receiving everything i used the code from that site i uploaded it to.
At this point I am completely confused about the state of your project and what you want me to help you with. I have already told you the changes I made to your code, and I am not sure what your problem is. Do you want me to re-post the exact code that I am using? I have used the exact code you posted with only modifications to the computer IDs and a substitute icbm.launch function -- which I have already documented for you. My code works.
What is it that you need?
#165183 Redirect Program to External Computer+Monitor
Posted by
surferpup
on 17 February 2014 - 03:21 PM
in
Ask a Pro
#165176 How to Exit from a While Loop
Posted by
surferpup
on 17 February 2014 - 01:59 PM
in
Tutorials
As you may be aware, a while loop has the structure:
while < some condition is true > do --various statements end
The logic of a while loop can be stated as:
- Test if a condition is logically true. If it is:
- do various statements until you encounter the end of this block (the end statement of the while ... do).
- Jump back up to the beginning of this block (the while statement)
- do various statements until you encounter the end of this block (the end statement of the while ... do).
- If the condition is not logically true, jump to the end of the while block and continue with the rest of the program.
There are two basic approaches to exiting a while loop. -- an exit condition in the while statement itself, or a break condition within the while loop's execution block. Let's try this out using key press events. We will exit if the user presses the "q" key.
Method One: Using an exitCondition within the while statement
local exitConditionVariable = false
while not exitConditionVariable do
print ("Waiting for a key press...")
local _,key = os.pullEvent("key")
if key == keys.q then
exitConditionVariable = true
end
print ("Hello from inside of the while loop")
end
print ("Done")
Method Two: Using an break statement inside of the while loop
The second way is to break out of a while loop when a condition occurs. This does not rely on variables external to the while loop. The break statement will move the program execution counter to one statement past the end statement of the while loop.
while true do -- do this forever
print ("Waiting for a key press...")
local _,key = os.pullEvent("key")
if key == keys.q then
break -- will exit the while loop
end
print ("Hello from inside of the while loop")
end
print ("Done")
A break statement is immediate. If you try these two versions out, you will find that the print statement print ("Hello from inside of the while loop") will execute one more time in the first example because the while loop will continue to finish execution of all the statements in the while loop before the while condition is tested again. In the break example, when the condition is satisfied, the while loop terminates immediately before printing "Hello from inside of the while loop".
Both are legitimate programming techniques which are used depending on what you as the programmer wish to accomplish.
In the first example, we wrote the exit condition as
while not exitConditionVariable do
Why didn't we just write while exitConditionVariable == false do ??
A variable can be logically false if it is nil or if it is assigned the value of false. However, a variable will equate (==) to false only if it is assigned the value of false. We cover the largest number of possibilities with the first example -- not exitConditionVariable will evaluate as true if exitConditionVariable is nil or if it holds a value of false. Because of this, we did not need to declare the variable and set its value before the while loop -- although it is better practice to do so.
If you are within a function (or program) and thinking of exiting a loop in the function (or program), the return keyword will immediately end execution of a loop much like a break will with the added bonus of returning from the function. This may be useful if your purpose is to immediately exit the loop and exit from the function. However, if your function returns values, you will need to handle that within the return statement. If you choose to use return for the purpose of ending loops, make sure that you truly intended to exit the function as well.
Furthermore, it is good to remember that whether you use break or you return, local variables fall out of scope when exiting the code block with which they are associated.
Additional tutorials that may be helpful if you had this question:
- For more on using break, see Lua Basics: Using break to Exit Loops
- For a good walkthrough of Lua basics, see Lua Basics -- Variable Scope, Code Blocks and Control Structures
#165169 Probably just a basic question
Posted by
surferpup
on 17 February 2014 - 01:18 PM
in
Ask a Pro
local exitConditionVariable = false
while not exitConditionVariable do
print ("Waiting for a key press...")
local _,key = os.pullEvent("key")
if key == keys.q then
exitConditionVariable = true
end
print ("Hello from inside of the while loop")
end
print ("Done")
The second way is to break out of a while loop when a condition occurs. This does not rely on variables external to the while loop. The break statement will move the program execution counter to one statement past the end statement of the while loop.
while true do -- do this forever
print ("Waiting for a key press...")
local _,key = os.pullEvent("key")
if key == keys.q then
break -- will exit the while loop
end
print ("Hello from inside of the while loop")
end
print ("Done")
A break statement is immediate. If you try these two versions out, you will find that the print statement print ("Hello from inside of the while loop") will execute one more time in the first example because the while loop will continue to finish execution of all the statements in the while loop before the while condition is tested again. In the break example, when the condition is satisfied, the while loop terminates immediately before printing "Hello from inside of the while loop".
Both are legitimate programming techniques which are used depending on what you as the programmer wish to accomplish.
In the first example, we wrote the exit condition as
while not exitConditionVariable do
Why didn't we just write while exitConditionVariable == false do ??
A variable can be logically false if it is nil or if it is assigned the value of false. However, a variable will equate (==) to false only if it is assigned the value of false. We cover the largest number of possibilities with the first example -- not exitConditionVariable will evaluate as true if exitConditionVariable is nil or if it holds a value of false. Because of this, we did not need to declare the variable and set its value before the while loop -- although it is better practice to do so.
#165166 The Complete Monitor Buttons and Control Tutorial Part III
Posted by
surferpup
on 17 February 2014 - 12:19 PM
in
Tutorials
Molinko, on 17 February 2014 - 02:51 AM, said:
You could change it so when inputting the color instead of colors.red the use can just choose his/her color like so 'white' .
I think that is an excellent suggestion for programming, especially if one is to turn this into an API. However, I can only focus on so many things when writing a tutorial to members and guests each of whom starts with whatever level of expertise they bring to the tutorial. This would be a good subject for a colors tutorial -- tips and tricks on handling colors in your programs.
Some people institute a color table or enumerator in their programs and use the string names of a color (i.e. "white") as key values. Others write out the full colors API call. Some would find your suggestion useful. I think what I will do is point out -- through this reply -- that you have an excellent idea, and I certainly encourage people to give your idea a try as they develop their skills in Lua. Thank you for the comment.
#165119 Ask A Pro Renewal Project (and How You Can Help!)
Posted by
surferpup
on 16 February 2014 - 11:14 PM
in
Ask a Pro
- ComputerCraft | Programmable Computers for Minecraft
- → surferpup's Content


