Jump to content




Peripheral:20: Expected String


  • You cannot reply to this topic
9 replies to this topic

#1 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 09 August 2013 - 10: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.

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 August 2013 - 10:38 AM

Presumably you are replacing the side variable with a literal string such as "left", yes?

#3 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 09 August 2013 - 10:47 AM

View PostBubba, on 09 August 2013 - 10:38 AM, said:

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?

#4 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 August 2013 - 10: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.

#5 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 August 2013 - 11:06 AM

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.

#6 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 09 August 2013 - 11:17 AM

The code is on pastebin: http://pastebin.com/21LS9UgT
The problem seems to be in the function clear(). No idea why.

#7 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 August 2013 - 11:29 AM

View PostGamerNebulae, on 09 August 2013 - 11:17 AM, said:

The code is on pastebin: http://pastebin.com/21LS9UgT
The 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.

#8 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 August 2013 - 11:45 AM

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.

#9 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 09 August 2013 - 12:00 PM

View PostBubba, on 09 August 2013 - 11:45 AM, said:

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.

#10 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 09 August 2013 - 12:15 PM

Dang it! still the same error while I fixed the code. I updated the pastebin link: http://pastebin.com/21LS9UgT





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users