215 posts
Location
Netherlands
Posted 09 August 2013 - 11:16 AM
Hi everybody,
I have been playing around with the peripheral API and for some reason, two EXACTLY the same pieces of code give me trouble. For some odd reason it works on one Computer and it doesn't work on the other. This is the piece of code:
data = peripheral.getNames(side)
for i,j in pairs(data) do
type_peripheral = peripheral.getType(j)
print(i..": "..type_peripheral)
if type_peripheral == "monitor" then
mon = peripheral.wrap(data[i])
end
end
And for some reason this works on the other Computer:
data = peripheral.getNames(side)
for i,j in pairs(data) do
type_peripheral = peripheral.getType(j)
print(i..": "..type_peripheral)
if type_peripheral == "monitor" then
mon = peripheral.wrap(data[i])
mon.clear()
mon.write("Hello World!")
end
end
I hope you can help me.
1190 posts
Location
RHIT
Posted 09 August 2013 - 11:38 AM
Presumably you are replacing the side variable with a literal string such as "left", yes?
215 posts
Location
Netherlands
Posted 09 August 2013 - 11:47 AM
Presumably you are replacing the side variable with a literal string such as "left", yes?
What you would get back is a table looking like this:
1: back
2: left
So what I would do is select the right type of peripheral from that list. Thinking about it, wouldn't a tostring() work?
1190 posts
Location
RHIT
Posted 09 August 2013 - 11:54 AM
-snip-
Nevermind. peripheral.getNames does not take any arguments. Why are you providing it with arguments in the first line? I guess it doesn't matter. Let me look over the code again and I'll try to see what's going on.
1190 posts
Location
RHIT
Posted 09 August 2013 - 12:06 PM
Okay, well your code works for me and I see no reason that it should not work for you. Have you just typed the program up on the forums rather than paste the actual code? Because if so you may have typos that are not present in the code you gave here.
215 posts
Location
Netherlands
Posted 09 August 2013 - 12:17 PM
The code is on pastebin:
http://pastebin.com/21LS9UgTThe problem seems to be in the function clear(). No idea why.
1190 posts
Location
RHIT
Posted 09 August 2013 - 12:29 PM
The code is on pastebin:
http://pastebin.com/21LS9UgTThe problem seems to be in the function clear(). No idea why.
Actually, I realized that it's giving the line number for the peripheral API, not your program. Line 20 in the peripheral api is referring to peripheral.isPresent, so I'm not sure what's going on there.
1190 posts
Location
RHIT
Posted 09 August 2013 - 12:45 PM
Okay, the error is not occurring in the snippet that you originally posted, but rather in the function liquidDrawBar. First thing, you named the variable that the function takes "table". This is a bad practice, because table is a preset variable and when you override it you disable all the functionality given to you by the table var for the rest of that function.
The actual error though is caused by this:
information_reader = peripheral.wrap(progress_bar["side"])
You never declare a side variable inside of liquidTable.
215 posts
Location
Netherlands
Posted 09 August 2013 - 01:00 PM
Okay, the error is not occurring in the snippet that you originally posted, but rather in the function liquidDrawBar. First thing, you named the variable that the function takes "table". This is a bad practice, because table is a preset variable and when you override it you disable all the functionality given to you by the table var for the rest of that function.
The actual error though is caused by this:
information_reader = peripheral.wrap(progress_bar["side"])
You never declare a side variable inside of liquidTable.
*facepalm across the universe* Thanks, Bubba! Didn't know I could be that stupid.
215 posts
Location
Netherlands
Posted 09 August 2013 - 01:15 PM
Dang it! still the same error while I fixed the code. I updated the pastebin link:
http://pastebin.com/21LS9UgT