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

Peripheral :20: Expected String

Started by LightBringer, 08 February 2014 - 01:56 PM
LightBringer #1
Posted 08 February 2014 - 02:56 PM
Hi, so I am new at programming (try a week and a half new) and have been only using computercraft actively (other than using the tunnel program on a mining turtle) just as long. I have been playing with computercraft on the tekkit platform which currently uses minecraft 1.5.2. . Tekkit uses open peripheral so I am writing a program to retrieve info from a connected redstone energy cell and send it to a specific connected/networked monitor. I have had a few problems along the way but generally I have been able fix them on my own with a bit of reading. This one however I can't find useful information on it
Peripheral :20: Expected string 

I read another page on it but it was never resolved, also I wanted to know of any other errors I may have missed in writing the code (I know most of the broader principles but some of the finer points are difficult for me). This is the pastebin link

http://pastebin.com/mXJy654V


Notes: Yes, I checked 15 times to make sure the modems were connected and active, I also used the Lua prompt and was able to manually run methods and apis like print(), getType(), and setCursorBlink() (with arguments of course). on the networked monitors without issue.

Lines 44, and 45 are purely diagnostic, I was trying to figure out how the program was interpreting those variables since one of the previous problems was that It could not locate or get the type of peripheral the monitor was, this may still be the case still but I can't tell since I can't get around the previously mentioned error.

I know that the functions are out of order, I built this off of a program I wrote previously which did roughly the same thing but only for a terminal/computer, this was made so I can send the info to a networked monitor.

Side Questions: How do you make a program so it accepts extra user arguments, eg, in the case of the copy, "copy <source> <destination>" I already know how to do the first one using

local variable =...
but I don't know how to add a second or any more after that

Can you send a program directly to a networked monitor using its ID in a similar fashion to the monitor program, that might make things much simpler.

any help is appreciated.
CometWolf #2
Posted 08 February 2014 - 08:04 PM
Here's your problem

local mntr=monitor_3
local ntwk=peripheral.wrap(mntr)

if peripheral.getType(mntr) == "monitor" then
the peripheral wrap argument must be a string. In this case, the mntr should be local mntr="monitor_3". Same thing goes for getType.

To use a variable amount of user arguments, you need to index them in a table and retreive as nessacary

local tArg = {...} --index arguments in a table
print(tArg[1]) -- printing the first argument
print(tArg[2]) -- printing the second argument

And that last question… wat? Monitors do not run programs, they merely draw what a connected computer tells them to. This is what the peripheral.wrap is for. It returns a table of functions that are pretty much identical to the ones used on the terminal, when used on a monitor. The only difference is an added setTextScale, which changes the monitor resolution. Also there is no print for monitors, how the hell did you call print on a networked monitor?

local mon = peripheral.wrap("monitor_3")
mon.write"HELLO"
mon.setCursorPos(1,2)
mon.setTextColor(colors.blue) -- change color
mon.write"I AM A MONITOR!"
Edited on 08 February 2014 - 07:10 PM
awsmazinggenius #3
Posted 08 February 2014 - 10:44 PM

local mon = peripheral.wrap("monitor_3")
mon.write"HELLO"
mon.setCursorPos(1,2)
mon.setTextColor(colors.blue) -- change color
mon.write"I AM A MONITOR!"
When using the no-parenthesis rule I believe you still need a space between mon.write and "HELLO". Correct me if I'm wrong, but either way it makes your code a tad bit more readable.
Bomb Bloke #4
Posted 08 February 2014 - 10:50 PM
Correct me if I'm wrong
No space is required.
awsmazinggenius #5
Posted 08 February 2014 - 10:54 PM
Oh, silly me :)/>
LightBringer #6
Posted 08 February 2014 - 11:32 PM
First off, thanks CometWolf, those tips helped a-lot, I got it to work now. Second, Correct, however I wasn't trying to get the monitor to run a program, the "monitor" program (if you look in the programs index which is shown by typing "programs" into the terminal, it is listed there) displays whatever would be shown on the terminal, on the monitor. The "monitor" program accepts arguments for side(that the monitor is on) and program name(the program that you want the information from, that would normally be displayed on the terminal screen). I was curious if the monitor program or a similar program would accept arguments for monitor IDs instead of, or as well as sides. I already knew that peripherals can't run programs. Sorry about that, I meant "write", I always get "write" and "print" mixed up It's quite frustrating having a program/command fail on you because you used a a word that means exactly the same thing in real life, but the computer cannot reconcile the seemingly trivial difference between the two. :unsure:/>
CometWolf #7
Posted 09 February 2014 - 04:15 AM
I've never used the monitor program myself, wasn't even aware it existed lol. Anyways, yeah it should work just fine with networked monitors.
Edited on 09 February 2014 - 03:16 AM