2 posts
Posted 19 October 2012 - 01:20 AM
I'm using computer craft 1.3
i just made this code and i keep getting this error
Bios:206: [string "3x3"] :24: '='expected
local i
term.write("Enter Number: ")
i = read()
for i = 0, i do
turtle.detect()
if true then
turtle.dig()--1st layer
end
turtle.forward()
turtle.turnRight()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.detect()
if true then
turtle.dig()
end
turtle.detectUp()
if true then
turtle.digUp
end
turtle.up()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnRight()
turtle.turnRight()
turtle.detect()
if true then
turtle.dig()
end
turtle.detectUp()
if true then
turtle.digUp
end
turtle.up()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnRight()
turtle.down()
turtle.down()
end
1548 posts
Location
That dark shadow under your bed...
Posted 19 October 2012 - 01:30 AM
if true then
turtle.digUp
end
you forgot the brackets there
local i
term.write("Enter Number: ")
i = read()
for i = 0, i do
turtle.detect()
if true then
turtle.dig()--1st layer
end
turtle.forward()
turtle.turnRight()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.detect()
if true then
turtle.dig()
end
turtle.detectUp()
if true then
turtle.digUp()
end
turtle.up()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnRight()
turtle.turnRight()
turtle.detect()
if true then
turtle.dig()
end
turtle.detectUp()
if true then
turtle.digUp
end
turtle.up()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.detect()
if true then
turtle.dig()
end
turtle.turnRight()
turtle.down()
turtle.down()
end
EDIT: there are a few problems in the code as well
turtle.detect()
if true then
turtle.dig()
end
will always dig. the correct usage is
if turtle.detect() then
turtle.dig()
end
2 posts
Posted 19 October 2012 - 02:00 AM
OK thank you for the help. :P/>/>
16 posts
Location
Wexford, Ireland
Posted 19 October 2012 - 02:19 PM
This makes no sense
i = read()
for i = 0, i do
You give i a value and then you change it again to 0 if the first loop runs.
1548 posts
Location
That dark shadow under your bed...
Posted 20 October 2012 - 01:45 PM
it isn't good coding procedure but it will probably work… now that you mention it I could actually use a similar technique to clean up a few scripts
2005 posts
Posted 20 October 2012 - 05:33 PM
You're kidding, right? It's super confusing, that's like the opposite of cleaning.
But yeah, it does work. Loop i is limited in scope to inside the loop, and doesn't start getting used until after "do". And I'm not really one to cast stones about confusing code.
1548 posts
Location
That dark shadow under your bed...
Posted 22 October 2012 - 05:09 AM
You're kidding, right? It's super confusing, that's like the opposite of cleaning.
But yeah, it does work. Loop i is limited in scope to inside the loop, and doesn't start getting used until after "do". And I'm not really one to cast stones about confusing code.
lol I know. but in some situations it may help to avoid declaring too many variables. depends on how you use it
2005 posts
Posted 22 October 2012 - 05:19 AM
I generally try to reserve i, j, k, and v for use in the various for loops. And as long as you're using scope effectively, there is no too many variables.
Then again, I'm always going crazy with the tables, so I really don't tend to come up against problems of cluttered namespaces. It depends on individual style, I guess.
1548 posts
Location
That dark shadow under your bed...
Posted 22 October 2012 - 05:34 AM
I use descriptive names for those vars. in a user system you use the username as the key and the password as the value so
local tUsers={KaoS='zxcv';Boris='6254837283'}
write('Username: ')
local user=read()
print('Password: ')
local pass=read()
for sUser,sPass in pairs(tUsers) do
if sUser==user and sPass==pass then
--login
end
end
I know in this case I don't actually have to go through the entire table as I can just use the username to access the password but it was just to show you what I mean :)/>/>
I'm a big fan of tables too. you can use metatables to make incredible functions