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

I do not understand this error, help me !

Started by leonek68, 20 August 2014 - 06:57 AM
leonek68 #1
Posted 20 August 2014 - 08:57 AM
This is my prog. :
  • print("Cash register 1")
  • print("Owner : leonekmi")
  • print("Scan your card")
  • reader = peripheral.wrap("right")
  • reader.setInsertCardLight(true)
  • local event, data = os.pullEvent()
  • if data == "0000leonekmi" then
  • print("Cash Register ready")
  • mon = peripheral.wrap("top")
  • read = peripheral.wrap("left")
  • reader.setInsertCardLight(false)
  • else
  • print("Invalid card")
  • reader.setInsertCardLight(false)
  • error("Invalid card")
  • end
  • local value = read() – My program crash at this line.+

Help me !

Thanks !
KingofGamesYami #2
Posted 20 August 2014 - 02:06 PM
You redifined read:

read = peripheral.wrap("left")

You can't call a peripheral.

For future referance:
Post the full error
put your code between
 -thecode- 
(without the spaces)
leonek68 #3
Posted 21 August 2014 - 02:58 PM
I write in my prog.

value1 = read()

And my program crash

prog:1: attempt to call table
leonek68 #4
Posted 21 August 2014 - 03:05 PM
My prog has crashed to the same error


print("Cash register 1")
print("Owner : leonekmi")
print("Scan your card")
reader = peripheral.wrap("right")
reader.setInsertCardLight(true)
event, data = os.pullEvent()
if data == "0000leonekmi" then
  print("Cash Register ready")
  mon = peripheral.wrap("top")
  reader2 = peripheral.wrap("left")
  reader.setInsertCardLight(false)
  else
  print("Invalid card")
  reader.setInsertCardLight(false)
  error("Invalid card")
end

print("Amount :")
value = read()

And error is

program:22: attempt to call table
theoriginalbit #5
Posted 21 August 2014 - 03:22 PM
It is a good idea when requesting help on these forums to post your code so that we can assist you faster and easier.

The error you're getting means that you have a variable (more specifically a table) defined somewhere called read which is overriding ComputerCraft's read function. You cannot have multiple things named the same.
Lyqyd #6
Posted 21 August 2014 - 03:24 PM
That program doesn't even have 22 lines, so it would be impossible for it to throw that error.
theoriginalbit #7
Posted 21 August 2014 - 03:25 PM
Merged threads, please stick to one thread per program/problem, it allows us to easier keep track of your problem and give you the best advice possible.
KingofGamesYami #8
Posted 21 August 2014 - 03:49 PM
My prog has crashed to the same error


print("Cash register 1")
print("Owner : leonekmi")
print("Scan your card")
reader = peripheral.wrap("right")
reader.setInsertCardLight(true)
event, data = os.pullEvent()
if data == "0000leonekmi" then
  print("Cash Register ready")
  mon = peripheral.wrap("top")
  reader2 = peripheral.wrap("left")
  reader.setInsertCardLight(false)
  else
  print("Invalid card")
  reader.setInsertCardLight(false)
  error("Invalid card")
end

print("Amount :")
value = read()

And error is

program:22: attempt to call table

I bet you need to restart the computer. Since you used global variables (not a good idea), the global "read" function was overwritten when you ran your first code. Either shutdown the computer you are testing on or make a new one.
Dog #9
Posted 21 August 2014 - 07:34 PM
My prog has crashed to the same error



And error is

program:22: attempt to call table

I bet you need to restart the computer. Since you used global variables (not a good idea), the global "read" function was overwritten when you ran your first code. Either shutdown the computer you are testing on or make a new one.

KingofGamesYami makes a good point - you *should* localize your varaibles. However, I don't see where 'read' is being overwritten in the posted code (it was being overwritten in the original code). I see 'reader' as a variable, but I don't see 'read' being referenced anywhere. Also, that code is only 19 lines long so, as Lyqyd said, getting the error you reported on that code is impossible. Please post the entire code.
Edited on 21 August 2014 - 05:34 PM
0099 #10
Posted 22 August 2014 - 01:45 PM
KingofGamesYami makes a good point - you *should* localize your varaibles. However, I don't see where 'read' is being overwritten in the posted code (it was being overwritten in the original code). I see 'reader' as a variable, but I don't see 'read' being referenced anywhere. Also, that code is only 19 lines long so, as Lyqyd said, getting the error you reported on that code is impossible. Please post the entire code.

Dog, the original code was running on the same computer, on the same LuaVM, with the same global space. It can be polluted once and affect all the programs you are trying to run. That's why "os.pullEvent = os.pullEventRaw" trick affects the whole computer. After restart CraftOS brings all of the functions back.
Dog #11
Posted 22 August 2014 - 05:14 PM
KingofGamesYami makes a good point - you *should* localize your varaibles. However, I don't see where 'read' is being overwritten in the posted code (it was being overwritten in the original code). I see 'reader' as a variable, but I don't see 'read' being referenced anywhere. Also, that code is only 19 lines long so, as Lyqyd said, getting the error you reported on that code is impossible. Please post the entire code.

Dog, the original code was running on the same computer, on the same LuaVM, with the same global space. It can be polluted once and affect all the programs you are trying to run. That's why "os.pullEvent = os.pullEventRaw" trick affects the whole computer. After restart CraftOS brings all of the functions back.
0099 - thanks for the explanation, but I'm clear on the difference between local and global space. What I missed was the use of 'read' in the original post - now I see where things went awry.