Dog, on 28 July 2015 - 04:22 PM, said:
Welcome to the CC forums, TheHackerPlayer.
I noticed a few errors in your code. The first is that you spelled peripheral incorrectly for all your wraps and you aren't actually wrapping anything since you're defining your variables as strings (by putting their values in quotes).
Also, read() returns a string and peripheral wraps are essentially variables that point to tables, not strings, so you can't use your read() input to directly select a monitor like you're trying to do.
You might want to try a simple, straight forward approach like this...
term.clear()
up = peripheral.wrap("top") --# note that the only string we use here is to define which side the monitor is on
... --# rest of top code here
d = string.lower(read()) --# we convert our input to lower case so comparison is easier
if d == "up" then --# now we compare our input to find what the user selected and set the monitor variable to point to the correct wrapped monitor
monitor = up
elseif d == "down" then
monitor = down
elseif d == "right" then
monitor = right
elseif d == "left" then
monitor = left
end
... --# rest of bottom code here
t = read()
monitor.write(t)
This won't prevent someone from entering an invalid side or handle misspellings, etc., so keep that in mind, but this should provide a basic framework to get you started.
Thanks. Now I see my error. I am still newb at lua and improving. This is my first lua script....
Cranium, on 28 July 2015 - 04:23 PM, said:
Calm the flip down. He did exactly that, showing where your error was.
I just noticed he fixed my spelling, string points to table, and more. I'm still newb, so i kinda know what they're talking about.
KingofGamesYami, on 28 July 2015 - 03:52 PM, said:
Actually, the error should be
writemonitor:14:attempt to index ? (a string value)
..Because you are trying to index a string on line 14.
term.clear() --#clear the terminal
up = "perhiperal.wrap(top)" --#make some useless strings (consider actually calling peripheral.wrap)
down = "perhiperal.wrap(bottom)"
left = "perhiperal.wrap(left)"
right = "perhiperal.wrap(right)"
term.setCursorPos(18,1) --#set the cursor position
print("What direction?")
d = read() --#get a string input from the user
term.clear() --#clear the terminal again
term.setCursorPos(13,1) --#move the cursor again
print("What Would You Like To Say?")
t = read() --#get another string input from the user
monitor = d --#set a variable equal to another variable (redundant and useless)
monitor.write(t) --#treat the earlier string you got from the user as if it were a wrapped monitor object. Which it is not.
Umm, I just noticed that you fixed my spelling error, useless stuff and more. Sorry if it seemed like I was yelling at you, I just didn't understand (I'm a newb) and I got confused.
Edited by Cranium, 28 July 2015 - 05:16 PM.