92 posts
Posted 08 September 2012 - 05:39 PM
I have this program for making my RedPower frame quarry work - and I used ComputerCraft since Lua is a LOT easier than Forth - but I got the error in the title. Can anyone help me? Here's the script:
I forgot how you do the code thingy - the button didn't like me.
function usage()
print 'Usage:'
print 'bore 10 - bores a hole 10 blocks deep'
print 'type bore followed by a number to bore a hole'
end
tArgs = { ... }
if #tArgs == 1 then
if tonumber(tArgs[1]) then
digHeight = tArgs[1]
boreDown()
else
usage()
end
else
usage()
end
function boreDown()
while ( digHeight =~ 0 ) do
redstone.SetBundledOutput('back', 1)
sleep(0.800)
redstone.SetBundledOutput('back', 2)
sleep(0.800)
redstone.setBundledOutput('back', 4)
sleep(0.800)
digHeight = (digHeight - 1)
end
print 'Completed tunnel boring'
end
Wait. First error I noticed: it's redstone.setBundledOutput, not redstone.SetBundledOutput…
209 posts
Location
In your fridge.
Posted 08 September 2012 - 05:45 PM
Remove the perenthesis on your while statement. You don't need parenthesis there. And I agree, Lua is easier to use AND more widespread than FORTH.
92 posts
Posted 08 September 2012 - 05:46 PM
Remove the perenthesis on your while statement. You don't need parenthesis there. And I agree, Lua is easier to use AND more widespread than FORTH.
I tried that and now i'm getting the error expecting a do in the same line
209 posts
Location
In your fridge.
Posted 08 September 2012 - 05:49 PM
Is there a 'do' on that line?
92 posts
Posted 08 September 2012 - 05:50 PM
Is there a 'do' on that line?
I meant -
function usage()
print 'Usage:'
print 'bore 10 - bores a hole 10 blocks deep'
print 'type bore followed by a number to bore a hole'
end
tArgs = { ... }
if #tArgs == 1 then
if tonumber(tArgs[1]) then
digHeight = tArgs[1]
boreDown()
else
usage()
end
else
usage()
end
function boreDown()
while digHeight =~ 0 do --Here it is expecting the do
redstone.setBundledOutput('back', 1)
sleep(0.800)
redstone.setBundledOutput('back', 2)
sleep(0.800)
redstone.setBundledOutput('back', 4)
sleep(0.800)
digHeight = (digHeight - 1)
end
print 'Completed tunnel boring'
end
1688 posts
Location
'MURICA
Posted 08 September 2012 - 05:53 PM
Your inequality sign is backwards.
while digHeight =~ 0 do
should be
while digHeight ~= 0 do
92 posts
Posted 08 September 2012 - 05:54 PM
Your inequality sign is backwards.
while digHeight =~ 0 do
should be
while digHeight ~= 0 do
Ah. Thanks. I actually forgot howto do the inequality signs since i haven't used Lua for a long time.
>.< Now it's erroring that :
bore:10: attempt to call nil
which is where the function to start tunnel boring is.. it's saying the function is nonexistant? Oh wait. I can guess why. The function needs to be at the start?
Edited on 08 September 2012 - 03:56 PM
1688 posts
Location
'MURICA
Posted 08 September 2012 - 05:57 PM
I used to make the mistake all the time too. When I use them, I usually think "is almost equal to" since that's what I was taught the symbol meant before I knew about lua.
"is almost (~) equal (=) to" helped me distinguish the order.
Hope this helps in the future :D/>/>
You could always replace "almost" with "not" to make things less confusing though, that's just my backwards logic, haha.
474 posts
Posted 08 September 2012 - 07:26 PM
Here ya go:
tArgs = { ... }
function usage()
print 'Usage:'
print 'bore 10 - bores a hole 10 blocks deep'
print 'type bore followed by a number to bore a hole'
end
function boreDown()
while digHeight ~= 0 do
redstone.setBundledOutput('back', 1)
sleep(0.800)
redstone.setBundledOutput('back', 2)
sleep(0.800)
redstone.setBundledOutput('back', 4)
sleep(0.800)
digHeight = digHeight-1
end
print 'Completed tunnel boring'
end
if #tArgs == 1 then
if tonumber(tArgs[1]) then
digHeight = tonumber(tArgs[1])
boreDown()
else
usage()
end
else
usage()
end