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

Help pleasr

Started by tomtom6695, 13 December 2012 - 08:49 AM
tomtom6695 #1
Posted 13 December 2012 - 09:49 AM
Can someone please help. I have wrote a program and I don't know lua very well, so I may have made a rookie mistake :(/>

it is code to make a simple stripmine. I would like you to tell me what i am doing wrong, not to improve the system because I am trying to learn the programming language

Sorry for no annotations.


const MineGap = 3
const TunnelLen = 29
fuelslot = 16
lightslot = 15
light = 10
lightCounter = 0
Local MineAmount = read() - 1
StripMine()
function Checkfuel()
if turtle.getfuellevel() < 1 then
  turtle.select(fuelslot)
  turtle.refuel
end
end
function LightPlace()
if lightcounter = light then
  turtle.select(lightslot)
  turtle.placeup()
  lightcounter = 0
end
end
function ComeBack()
turtle.turnright()
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  turtle.forward()
end
end
function Mine()
Checkfuel()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
  turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Minenext()
Checkfuel()
  turtle.turnright()
turtle.forward(MineGap)
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
   turtle.forward()
  while turtle.detectup() == true do
   turtle.digup
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
Function StripMine()
CheckFuel()
Mine()
for i=1,MineAmount  do
  Minenext()
end
end

Please check the latest version down the page!!!
anonimo182 #2
Posted 13 December 2012 - 09:53 AM
1. Did you already tried the code?
2. Put the code in code tags please…

Edit: I found two errors: 1. don't put a -1 next to read
2. put the functions at the beggining, not at the end :)/>
tomtom6695 #3
Posted 13 December 2012 - 10:08 AM

function LightPlace()
if lightcounter = light then
  turtle.select(lightslot)
  turtle.placeup()
  lightcounter = 0
end
end
function ComeBack()
turtle.turnright()
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  turtle.forward()
end
end
function Mine()
Checkfuel()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
  turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Minenext()
Checkfuel()
  turtle.turnright()
turtle.forward(MineGap)
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
   turtle.forward()
  while turtle.detectup() == true do
   turtle.digup
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
Function StripMine()
CheckFuel()
Mine()
for i=1,MineAmount  do
  Minenext()
end
end
function Checkfuel()
if turtle.getfuellevel() < 1 then
  turtle.select(fuelslot)
  turtle.refuel
end
end

const MineGap = 3
const TunnelLen = 29
fuelslot = 16
lightslot = 15
light = 10
lightCounter = 0
Local MineAmount = read()
MineAmount = MineAmount - 1
StripMine()

I have changed it but it says that ":2: 'then' expected"
tomtom6695 #4
Posted 13 December 2012 - 10:16 AM
I have edited it again and now it says line 58 needs an "=" but it is a function :angry:/>

function LightPlace()
if lightcounter == light then
  turtle.select(lightslot)
  turtle.placeup()
  lightcounter = 0
end
end
function ComeBack()
turtle.turnright()
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  turtle.forward()
end
end
function Mine()
Checkfuel()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
  turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Minenext()
Checkfuel()
  turtle.turnright()
turtle.forward(MineGap)
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
   turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
Function StripMine()
CheckFuel()
Mine()
for i=1,MineAmount  do
  Minenext()
end
end
function Checkfuel()
if turtle.getfuellevel() < 1 then
  turtle.select(fuelslot)
  turtle.refuel
end
end

const MineGap = 3
const TunnelLen = 29
fuelslot = 16
lightslot = 15
light = 10
lightCounter = 0
Local MineAmount = read()
MineAmount = MineAmount - 1
StripMine()
OmegaVest #5
Posted 13 December 2012 - 10:16 AM
Comparisons require == instead of just =.

EDIT: Wow, ninja'd by the OP fixing their own problem. That's a new one.
bjornir90 #6
Posted 13 December 2012 - 10:17 AM

function LightPlace()
if lightcounter = light then
  turtle.select(lightslot)
  turtle.placeup()
  lightcounter = 0
end
end
function ComeBack()
turtle.turnright()
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  turtle.forward()
end
end
function Mine()
Checkfuel()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
  turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Minenext()
Checkfuel()
  turtle.turnright()
turtle.forward(MineGap)
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
   turtle.forward()
  while turtle.detectup() == true do
   turtle.digup
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
Function StripMine()
CheckFuel()
Mine()
for i=1,MineAmount  do
  Minenext()
end
end
function Checkfuel()
if turtle.getfuellevel() < 1 then
  turtle.select(fuelslot)
  turtle.refuel
end
end

const MineGap = 3
const TunnelLen = 29
fuelslot = 16
lightslot = 15
light = 10
lightCounter = 0
Local MineAmount = read()
MineAmount = MineAmount - 1
StripMine()

I have changed it but it says that ":2: 'then' expected"
You need 2 = in the if statement like this :
If somVar == someOthervar then
tomtom6695 #7
Posted 13 December 2012 - 10:40 AM
I have but now it says the function is wrong "Stripmine1" it says = expected




function LightPlace()
if lightcounter == light then
  turtle.select(lightslot)
  turtle.placeup()
  lightcounter = 0
end
end
function ComeBack()
turtle.turnright()
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  turtle.forward()
end
end
function Mine()
Checkfuel()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
  turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Minenext()
Checkfuel()
  turtle.turnright()
turtle.forward(MineGap)
turtle.turnright()
for i=1,TunnelLen do
  checkfuel()
  while turtle.detect() == true do
   turtle.dig()
   sleep(0.25)
  end
   turtle.forward()
  while turtle.detectup() == true do
   turtle.digup()
   sleep(0.25)
  end
  lightcounter = lightcounter + 1
  LightPlace()
end
ComeBack()
end
function Checkfuel()
if turtle.getfuellevel() < 1 then
  turtle.select(fuelslot)
  turtle.refuel(1)
end
end
Function StripMine1()
CheckFuel()
MineAmount = MineAmount - 1
Mine()
for i=1,MineAmount  do
  Minenext()
end
end
local MineGap = 3
local TunnelLen = 29
fuelslot = 16
lightslot = 15
light = 10
lightCounter = 0
MineAmount = read()
StripMine1()
OmegaVest #8
Posted 13 December 2012 - 10:59 AM
Function should be function. Lower case.
tomtom6695 #9
Posted 13 December 2012 - 11:04 AM
Function should be function. Lower case.
For god's sake

But there is a problem with the Checkfuel
OmegaVest #10
Posted 13 December 2012 - 11:07 AM
Yeah, capitalization issues again.

turtle.getFuelLevel()


In fact, go through your code. Wherever you have a function name, make it format to:

word.firstSecondThird()

So that every "word" after the first in its name is denoted with a capital.
tomtom6695 #11
Posted 13 December 2012 - 11:30 AM
I really don't like this programming language. Visual basic for me :)/> No grammatical errors in there
tomtom6695 #12
Posted 13 December 2012 - 11:47 AM
I have fixed the words but now it keeps on saying "nil value called"
OmegaVest #13
Posted 13 December 2012 - 11:50 AM
What line?

And by that, I mean what does that line say?
tomtom6695 #14
Posted 13 December 2012 - 12:10 PM
It's OK I have fixed it. it was another Grammar error c should have been C. Is there an easy way to get your program to stay on when you pick up the turtle because i keep have to copy the file back in the computer folder
anonimo182 #15
Posted 13 December 2012 - 03:55 PM

while true do
--the program code
end
Or name the file "startup" without the "'s


Edit: Reread the post, label your computer, in the shell run label <yourName>