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

[Lua][Error]

Started by IceCrasher, 23 September 2012 - 08:05 PM
IceCrasher #1
Posted 23 September 2012 - 10:05 PM
Hi guys, I play computercraft since two days, so I'm not a really good programer, but I know you guys out there are awesome and I hope you will help my. (the name of my program is: calculate2)

After it printed "How much HVSolars do you have already?", I tiped in 5 and pressed enter, the computer gives my an error message:
calculate2:2: attempt to call nil

please help me:


print("How much HVSolars do you have already?")
a = tonuumber(read())

x     =     1
hv    = 12500
stop  = 0
power = 1000000
delay = 90
t     = 0
tt1   = 0
tt2   = 0
tt3   = 1
tt4   = 0

while stop == 0 do
   if tt3 > 0 then
      while x < a do
         tt1 = power / 512 / 20 / x * hv
         tt2 = tt1 - delay
         tt3 = tt2 / tt1
         x   = x + 1
         t   = t + tt1 + tt4
      end
   else
      print("Ab "..x.." ist tt3 =< als 0")
      stop = 1
   end
end

print(t.." sec")

tinm = t / 60
print(tinmin.." min")

tinh = tinm / 60
print(tinh.." h")

tind = tinh / 24
print(tind.." d")
MysticT #2
Posted 23 September 2012 - 10:07 PM
It's the 3-4 post about the same code, please just ask in the same thread instead of doing multiple ones with the same stuff.
The problem is that you wrote tonuumber instead of tonumber.

Edit: Also, I just noticed that your loop will never end. You set it to stop when tt3 is less or equal to 0, but the only change you do to it is dividing it, wich will never return 0. This will create an infinite loop that will crash the computer.
IceCrasher #3
Posted 23 September 2012 - 10:08 PM
thank you, ok I'll be more carefull…