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

FunshineX's RFID writer code issue

Started by :-), 09 March 2015 - 09:12 PM
:-) #1
Posted 09 March 2015 - 10:12 PM
isRunning = true
state = {"Ready", "Card Inserted", "Waiting for Data", "Busy...", "Done"}
curState = 1

function toPercent(num)
  num = num*100
  return math.floor(num+.5).."%"
end

writer = peripheral.wrap("left")

while isRunning do
  if not writer.isPresent() then

	curState = 1

  else	-- card present

	curState = 2

	if writer.getProgress() >= 0 then

	  curState = 4

	elseif writer.isCoded() then

	  curState = 5

	end

  end

  if curState == 2 then
	print("Blank Card Inserted. Enter data...")
	data = read
	print("Enter Label")
	label = read

	curState = 3

	sleep(2)
	writer.encode(data, label)
  end

  term.clear()
  term.setCursorPos(1,1)
  print(state[curState])
  if curState == 4 then
	print(toPercent(writer.getProgress()))
  end
  sleep(2)
end


Anything wrong? i personally think nothing is wrong, probably because im copying funshinex's writer code from youtube but getting the following error: rfidWriter:13: attempt to index ? (a nil value)
Edited on 09 March 2015 - 10:07 PM
HPWebcamAble #2
Posted 09 March 2015 - 11:31 PM
On the lines

data = read --# line 35

label = read --# line 37
You need to have 'read()', not 'read' to call it.


Now, your actual question.

Looks like line 13 is this:

if not writer.isPresent() then

That would throw an attempt to index nil if 'writer' is nil.
Above, you wrap 'writer' as the left peripheral. Is there actually a writer on the left?

After some hunting, I found the documentation for the mod its from:
http://www.computerc...ss-peripherals/
Edited on 09 March 2015 - 10:32 PM
:-) #3
Posted 09 March 2015 - 11:35 PM
That would throw an attempt to index nil if 'writer' is nil.
Above, you wrap 'writer' as the left peripheral. Is there actually a writer on the left?
yes there is if you look closely to the left you might be able to see another block. Thats the RFID writer

also this is not any of the listed versions…i actually am using 1.7.10

you also said about line 13 i compared the text and saw nothing different. maybe if you could point 1 or 2 lines above and below line 13 i might see the problem because i dont see anything wrong with that line
Edited on 09 March 2015 - 11:08 PM
:-) #4
Posted 10 March 2015 - 12:12 AM
ok i have corrected the data and label line but cant see the issue with line 13
HPWebcamAble #5
Posted 10 March 2015 - 12:24 AM
ok i have corrected the data and label line but cant see the issue with line 13

Well, I just saw the picture you attached to your previous post. That shows the reader is on the right

Change

writer = peripheral.wrap("left")

to


writer = peripheral.wrap("right")
Edited on 09 March 2015 - 11:27 PM
:-) #6
Posted 10 March 2015 - 12:47 AM
oh.. i got confused with left and right but thanks, i really wouldnt have noticed it. XD

also i would like to wire it to a monitor and make it so that you cant terminate it and it is the default start up file instead of opening up the command line
HPWebcamAble #7
Posted 10 March 2015 - 01:56 AM
i would like to wire it to a monitor and make it so that you cant terminate it and it is the default start up file instead of opening up the command line

You can have it display things on a monitor, but you'd have to still be able to access the computer to type in the data and label
The monitor API is the same as the term API, just wrap the monitor as a peripheral (Like you did with the writer)
(Here is the CC Wiki for monitors for reference: http://computercraft.info/wiki/Monitor )

To make it the startup file is really easy

rename <currentname> startup
When the computer turns on, it will run the startup
Edited on 10 March 2015 - 12:58 AM