Jump to content




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


  • You cannot reply to this topic
2 replies to this topic

#1 Leslieghf

  • New Members
  • 2 posts

Posted 16 August 2016 - 05: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()


#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 16 August 2016 - 06: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.

#3 Leslieghf

  • New Members
  • 2 posts

Posted 18 August 2016 - 10:17 AM

 Lupus590, on 16 August 2016 - 06:50 PM, said:

A solution, pass some values to task at the bottom of your code.

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users