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?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Gps Not Working
Started by cmckain14, 25 September 2013 - 10:52 PMPosted 26 September 2013 - 12:52 AM
I have building a mining program but the gps is reporting nil even though the debug reports a value.
Posted 26 September 2013 - 03:01 AM
Before this bit of code runs, what is by set to?
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.
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.
y = by --Backup for y print(y) --No value if y == nil then error("Nope, still lost :(/>/>/>/>") end
Posted 26 September 2013 - 03:40 AM
One small tidbit of feedback. You have two if statements to check one instance of user input. It is probably better to use 1 if block to check the one input.
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.
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.
Posted 26 September 2013 - 04:17 AM
More importantly though, what happens if they type "banana"?One small tidbit of feedback. You have two if statements to check one instance of user input. It is probably better to use 1 if block to check the one input.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.
Posted 26 September 2013 - 05:36 AM
More importantly though, what happens if they type "banana"?One small tidbit of feedback. You have two if statements to check one instance of user input. It is probably better to use 1 if block to check the one input.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.
Posted 26 September 2013 - 09:54 AM
But why is y nil when the GPS should define it?Before this bit of code runs, what is by set to?
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.y = by --Backup for y print(y) --No value if y == nil then error("Nope, still lost :(/>/>/>/>/>") end
Posted 26 September 2013 - 10:40 AM
by = y == y cord
y = by == nil
your backup is deleting the y cord.
smal derp
y = by == nil
your backup is deleting the y cord.
smal derp
Posted 27 September 2013 - 02:36 AM
Because you made it nil after that.But why is y nil when the GPS should define it?Before this bit of code runs, what is by set to?
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.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).