This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ontheworld's profile picture

[lua][error] error 338 problem

Started by ontheworld, 28 February 2013 - 09:12 AM
ontheworld #1
Posted 28 February 2013 - 10:12 AM
Title: [lua][error] error 338 problem

I'm trying to make a program for my turtle to mine me a mineshaft, but I can't run it. The error log says "bios:338: [string "dig"]:2: '=' expected". I know this pops up when you miss a parameter, but I can't figure it out :/

Here's the code:

once
turtle.refuel( 1 )
endonce
while j < 10 do
if turtle.getFuelLevel() < 10 then
turtle.refuel( 1 ) end
else
j = 0
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
j = j + 1
OmegaVest #2
Posted 28 February 2013 - 11:31 AM
Errrr. No.

once is not a command in Lua, so far as I know. If you want the program to run that line once, then you just need to call it once. Also, you have no end on your while loop, that I can see.

And, that error is not a parameter problem, I don't think. It mostly happens when you try to instantiate a variable and then don't give it a value.



…I think you should go look at the Lua Manual. Pay specific attention to the Loops section, and the If/else section. I think it will help better than I can.
LordIkol #3
Posted 28 February 2013 - 01:33 PM
Hi ontheworld,

you should look through some tutorials and scripts here in the forum to get some basics for loops and functions
here is a new version of your code that should do what you wanted to do.
put in some comments hope this helps you little bit for further code



turtle.refuel( 1 )

--making a function for tasks that come up often is always the best way
local function tFuel(amount)
while turtle.getFuelLevel() < 10 do --as long as fuellevel less than 10 refuel
turtle.select(1) --fuelslot needs to be selected 
turtle.refuel(amount)  --1 is not the slot its the amount to refuel
end
end

--again a function for moving and digging makes code shorter, better and easier to read
local function moveForward()
        while turtle.detect() do --as lpng as something is in the way dig! 
        turtle.dig()
        end
        moved = false -- set moved to false
        while not(moved) do -- if moved false try to move
tFuel(1) --put in fuelcheck to be sure you can move
                moved = turtle.forward() --set moved to the result of forwad() returns only true if can be done  
        end
        
end

for i=0, 10 do -- this is a for loop execute everything until end statement 10 times
moveForward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.digDown()

moveForward()
turtle.digUp()
turtle.digDown()

moveForward()
turtle.digUp()
turtle.digDown()

turtle.turnRight()
moveForward()
turtle.turnRight()

turtle.digUp()
turtle.digDown()
moveForward()
turtle.digUp()
turtle.digDown()
moveForward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
moveForward()
end
LordIkol #4
Posted 28 February 2013 - 01:40 PM
if you dont get it worked out try the program here