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

lua: prog.lua:14: attempt to perform arithmetic on local 'TgtGang' (a nil value)

Started by Leslieghf, 16 August 2016 - 04:54 PM
Leslieghf #1
Posted 16 August 2016 - 06:54 PM
I tried making a logistical centre which is made out of turtle who get items on request from better barrels and put em into a me system from ae2. This is the code and a website that analyses the code. It shows me an error. I found out it has the same error for all three functions: getdiffG, getdiffT and getdiffH. There are some german word but I think you might understand what I mean.
http://ideone.com/HuqzyU
  • Gang = 0
  • Tiefe = 0
  • Hoehe = 0
  • GangDiff = 0
  • TiefeDiff = 0
  • HoeheDiff = 0
  • Active = false
  • TgtGang = 5
  • TgtTiefe = 1
  • TgtHoehe = 3
  • –Gets the differential between the current Pos and
  • –the Target Pos
  • function getdiffG(Gang, TgtGang)
  • GangDiff = TgtGang-Gang
  • return GangDiff
  • end
  • –""
  • function getdiffT(Tiefe, TgtTiefe)
  • TiefeDiff = TgtTiefe-Tiefe
  • return TiefeDiff
  • end
  • –""
  • function getdiffH(Hoehe, TgtHoehe)
  • HoeheDiff = TgtHoehe-Hoehe
  • return HoeheDiff
  • end
  • –Makes the turtle move to the Target Pos
  • function move(GangDiff, TiefeDiff, HoeheDiff, TgtGang)
  • turtle.turnRight()
  • for i=1,GangDiff do
  • turtle.forward()
  • turtle.forward()
  • turtle.forward()
  • end
  • turtle.turnLeft()
  • for i=1,TiefeDiff do
  • turtle.forward()
  • end
  • for i=1,HoeheDiff do
  • turtle.up()
  • end
  • if TgtGang % 2 == 0 then
  • turtle.turnLeft()
  • else
  • turtle.turnRight()
  • end
  • return pos
  • end
  • –Returns the turtle to the starting position and rotation
  • function returner(TgtGang, TgtTiefe, TgtHoehe)
  • if TgtGang % 2 == 0 then
  • turtle.turnLeft()
  • else
  • turtle.turnRight()
  • end
  • for i=1,TgtHoehe do
  • turtle.down()
  • end
  • for i=1,TgtTiefe do
  • turtle.forward()
  • end
  • turtle.turnRight()
  • for i=1,TgtGang do
  • turtle.forward()
  • turtle.forward()
  • turtle.forward()
  • end
  • end
  • –Performs 1 Task and returns if it succeeded
  • function task(Gang, Tiefe, Hoehe, TgtGang, TgtTiefe, TgtHoehe, Quantity)
  • getdiffG(Gang, TgtGang)
  • getdiffT(Tiefe, TgtTiefe)
  • getdiffH(Hoehe, TgtHoehe)
  • move(GangDiff, TiefeDiff, HoeheDiff, TgtGang)
  • returner(TgtGang, TgtHoehe, TgtTiefe)
  • return done
  • end
  • task()
Lupus590 #2
Posted 16 August 2016 - 07:50 PM
The last line of your code calls the function task without passing any values for the parameters so the default to nil (or null in other languages). This is then passed to another function called getdiffG which subtracts the nil value with another nil value.

A solution, pass some values to task at the bottom of your code.
Leslieghf #3
Posted 18 August 2016 - 11:17 AM
A solution, pass some values to task at the bottom of your code.

I'm so stupid… How didn't I notice that. Thanks :)/>