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

[fixed][immibis's Peripherals] Attempt To Index ? (a Function Value)

Started by awsmazinggenius, 10 November 2013 - 03:12 PM
awsmazinggenius #1
Posted 10 November 2013 - 04:12 PM
Fixed - ThanksHi,

Lately I've been working with immibis's Peripherals in a CMP (creative multiplayer) environment. I keep getting theAttempt to index ? (a function value)error when I attempt to call any of the mag-strip reader's functions (I have wrapped the reader in the reader variable on top of the computer). However, when I get a brand new computer, open the Lua interpreter, and type the same commands, it works fine.
Here is my code:
Spoileros.pullEvent = os.pullEventRaw
reader = peripheral.wrap

write = …

if write == "on" then

term.clear()
term.setCursorPos(1, 1)
print("Enter Card Data")
data = io.read()
term.clear()
term.setCursorPos(1, 1)
print("Enter Label")
label = io.read()
term.clear()
term.setCursorPos(1, 1)
print("Swipe Now")
reader.beginWrite(data, label)
else
term.clear()
term.setCursorPos(1, 1)
while true do
event, p1, p2, p3 = os.pullEvent("mag_swipe")

if p1 == "awsmazinggenius.35495604" then
print(textutils.formatTime(os.time(), false)..": A valid swipe was entered.")
rs.setOutput("left", true)
sleep(3)
rs.setOutput("left", false)
else
print(textutils.formatTime(os.time(), false)..": An invalid swipe was entered.")
reader.setInsertCardLight(true)
sleep(0.5)
reader.setInsertCardLight(false)
end
end
end

I get events when cards are swiped, but I get the errors whenever I call the reader functions, and only on this one computer. All my startup program does is run that program. Am I making a mistake, or am I the victim of a bug?

MC: 1.6.4
CC: 1.5.7
Immibis's Peripherals: Not sure but using the RazeCraft modpack. (Couldn't find a 1.6.4 version on the thread.)
Edited on 10 November 2013 - 03:43 PM
Bomb Bloke #2
Posted 10 November 2013 - 04:25 PM
Seems you forgot to specify a side when wrapping to "reader".
awsmazinggenius #3
Posted 10 November 2013 - 04:42 PM
Thanks for your quick reply. Yes, indeed, I did make the silly mistake of forgetting the side to wrap the card reader to. The code works great now. Once again, thanks so much.
H4X0RZ #4
Posted 10 November 2013 - 05:33 PM
You should not override "write" globaly. It will stop the function "write" to work untill a reboot
awsmazinggenius #5
Posted 10 November 2013 - 08:34 PM
Oh, didn't realize by collecting my argument from the terminal as write that I was actually overwriting an important function. Thanks for letting me know, even when the issue is already fixed.