0

Everytime this program startup , the program runs after a server restart this error shows up:

startup:13: attempt to call nil

When i comment out that line of code the same happens to the line after that, and after that.

Until all those four lines are. (the round(math.floor) lines) Then the program starts.

The four variables is needed in the program so it wont run well with them commented out.

If i now uncomment those lines the program starts perfectly and everything works.

Any reason what im doing wrong?

Ethaan
  • 11,291
  • 5
  • 35
  • 45
  • 3
    Post [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) here, instead of a link. – Yu Hao Apr 14 '15 at 15:01
  • 1
    Functions must be defined before they are called (`round` is defined on line 72). Try adding `local round` on a line before `while true do` on line 5. – Adam Apr 14 '15 at 15:11
  • Since the suggestion solved your issue I posted it as an answer. – Adam Apr 14 '15 at 17:11

1 Answers1

3

Functions must be defined before they are called (round is defined on line 72, but called on line 5). You can declare a function prior to defining it:

function program()
    local round -- forward declaration
    while true do

        -- call function defined below
        turbEnergy = round(math.floor(turbine.getEnergyStored())/100000,1) 

        -- function definition
        function round(val, decimal)                
        end
Adam
  • 3,053
  • 2
  • 26
  • 29