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

"Attempt to call number" error when dealing with variables.

Started by NomNuggetNom, 13 July 2013 - 07:39 PM
NomNuggetNom #1
Posted 13 July 2013 - 09:39 PM
I currently have an XP turtle set up to collect experience, then enchant the books. I'm attempting to make him display a line, similar to the following:

Enchanted # books so far, and currently level #.

Here is my full code:

level = 0
local num = 0
num = 0
xp = peripheral.wrap("right")
xp.setAutoCollect(true)
while true do

-- Detect if it's level 30 and enchant
if xp.getLevels() > 30 then
  turtle.select(1)
  turtle.suckUp()
  drop = turtle.getItemCount(1) - 1
  turtle.dropUp( drop )
  xp.enchant(30)
  num = num + 1

-- Store the enchanted book
  turtle.drop()
  sleep(5)
end

-- Display
level = xp.getLevels()
term.setCursorPos(1, 1)
term.clear()
print("Enchanted " ..num "books so far, and currently level " ..level)
end

When the script runs, even without the additional level displaying (just print("Enchanted" ..num)), it returns an error saying the following:

27: attempt to call a number

In the lua prompt, I can run

print ( num )
and it will return the correct number. But I can't seem to use it with any sort of text. Any assistance would be apprecieated.
Lyqyd #2
Posted 15 July 2013 - 12:46 PM
Split into new topic.

You need the concatenation operator on both sides of the variable, not just one.
HurricaneCoder #3
Posted 17 July 2013 - 12:14 AM
this is what it should looks like for the printing
print("Enchanted " ..num.. "books so far, and currently level " ..level)