a = 0
print("Are there GPS satellites in the sky?")
input = read()
if input == "No" then
error("There must be a GPS system in place to use this program!")
end
if input == "Yes" then
local x, y, z = gps.locate(2,true)
y = by --Backup for y
print(y) --No value
if y == nil then
error("Nope, still lost :(/>/>")
end
for i = 1,tonumber(y) do --It says that y is not a number
turtle.digDown()
turtle.down()
repeat
if turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
a = a + 1
until a > 4
end
while by ~= 1 do
turtle.up()
by = by - 1
end
turtle.select(2)
turtle.placeDown()
end
Also, could I have some feedback on the code, please?
#1
Posted 25 September 2013 - 11:52 PM
#2
Posted 26 September 2013 - 02:01 AM
If you never set by, then by is nil. Then you do "y = by" so y is also nil. Then you error because y is nil.
cmckain14, on 25 September 2013 - 11:52 PM, said:
y = by --Backup for y
print(y) --No value
if y == nil then
error("Nope, still lost :(/>/>/>/>")
end
#3
Posted 26 September 2013 - 02:40 AM
input = read()
if input == "no" then
error("There must be a GPS system in place to use this program!")
elseif input == "yes" then -- or just simply else
--insert rest of code here
end
In this bit of code its not really a big deal but in the larger scheme of things its a good habit to get into.
#4
Posted 26 September 2013 - 03:17 AM
Luanub, on 26 September 2013 - 02:40 AM, said:
input = read()
if input == "no" then
error("There must be a GPS system in place to use this program!")
elseif input == "yes" then -- or just simply else
--insert rest of code here
end
In this bit of code its not really a big deal but in the larger scheme of things its a good habit to get into.
#5
Posted 26 September 2013 - 04:36 AM
immibis, on 26 September 2013 - 03:17 AM, said:
Luanub, on 26 September 2013 - 02:40 AM, said:
input = read()
if input == "no" then
error("There must be a GPS system in place to use this program!")
elseif input == "yes" then -- or just simply else
--insert rest of code here
end
In this bit of code its not really a big deal but in the larger scheme of things its a good habit to get into.
Or No/Yes instead of no/yes. Definitely could use some extra error checking/prevention.
It could look something like...
local input = string.lower(read()) --make the var local and convert to lower case
if input == "no" then
--error
elseif input == "yes" then
--run the code
else
error("Invalid answer")
end
There are also other ways to accomplish this but hopefully that shows the general idea.
#6
Posted 26 September 2013 - 08:54 AM
immibis, on 26 September 2013 - 02:01 AM, said:
If you never set by, then by is nil. Then you do "y = by" so y is also nil. Then you error because y is nil.
cmckain14, on 25 September 2013 - 11:52 PM, said:
y = by --Backup for y
print(y) --No value
if y == nil then
error("Nope, still lost :(/>/>/>/>/>")
end
#7
Posted 26 September 2013 - 09:40 AM
y = by == nil
your backup is deleting the y cord.
smal derp
#8
Posted 27 September 2013 - 01:36 AM
cmckain14, on 26 September 2013 - 08:54 AM, said:
immibis, on 26 September 2013 - 02:01 AM, said:
If you never set by, then by is nil. Then you do "y = by" so y is also nil. Then you error because y is nil.
cmckain14, on 25 September 2013 - 11:52 PM, said:
y = by --Backup for y
print(y) --No value
if y == nil then
error("Nope, still lost :(/>/>/>/>/>/>/>/>")
end
"by" is nil.
"y = by" sets "y" to whatever "by" is.
Therefore, "y = by" sets "y" to nil (in this program).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











