Displaying user input on a monitor.
#1
Posted 28 February 2013 - 08:58 AM
#2
Posted 28 February 2013 - 09:07 AM
#3
Posted 28 February 2013 - 10:34 AM
term.redirect(peripheral.wrap("top")) local yourInput = read()
#4
Posted 28 February 2013 - 10:40 AM
function getInput(side, x, y) m = peripheral.wrap(side) local input = "" term.setCursoros(x, y) m.setCursorPos(x, y) while true do event, param = os.pullEvent() if event == "char" then input = input..param --write should continue where it left off term.write(param) m.write(param) elseif event == "key" then if param == keys.delete then input = string.sub(input, 1, #input - 1) --don't forget the .." " -> that should remove the removed letter from the screen term.setCursorPos(x, y) term.write(input.." ") m.setCursorPos(x, y) m.write(input.." ") elseif param == keys.enter then return input end end end end
Note: This is not tested, it's a little late here...But it should actually work... ;D
EDIT: This program should write your input to the terminal and the monitor. Of course term.redirect is faster, but then you won't see what you just typed in as long as you look at the teminal...
You could use metatables and modify the term table to refer to multiple monitors, but I wouldn't recommend that as long as you are still a beginner in lua
#5
Posted 28 February 2013 - 10:43 AM
#6
Posted 28 February 2013 - 11:04 AM
Quote
Id have to retype all I have so far... I probably should have written it in a program outside of Minecraft first.
But basically it prints a line of text then asks for a password. If you type in the right one it prints another line of text saying it was accepted and if its wrong it rejects the password and shuts down the system.
#7
Posted 28 February 2013 - 11:07 AM
boudragon, on 28 February 2013 - 11:04 AM, said:
Quote
Id have to retype all I have so far... I probably should have written it in a program outside of Minecraft first.
But basically it prints a line of text then asks for a password. If you type in the right one it prints another line of text saying it was accepted and if its wrong it rejects the password and shuts down the system.
#8
Posted 28 February 2013 - 11:12 AM
mon.setCursorPos (1,4) mon.write ("Password: ") write "Password: " input = read("*") mon.setCursorPos (10,4) mon.write (input) if input == password then mon.setCursorPos (1,5) mon.write (" ") mon.setCursorPos (1,6) print " " print "Password Accepted.") mon.write ("Password Accepted") sleep (2) term.clear() mon.clear() mon.setCursorPos (1,1) else
::EDIT::
Was wondering too... is it possible to write a program that, at startup, makes it so the monitor ALWAYS displays what is being typed in the computer (computer also displays) instead of having to add it into each program?
#9
Posted 01 March 2013 - 02:55 AM
boudragon, on 28 February 2013 - 11:12 AM, said:
Was wondering too... is it possible to write a program that, at startup, makes it so the monitor ALWAYS displays what is being typed in the computer (computer also displays) instead of having to add it into each program?
Yes, it is. As I already said you'll have to use metatables for it. It is maybe a little complicated...I might wright an easy tutorial about this in the future, but for now, this is how it has to be in that case: (tested)
m = peripheral.wrap("left") function set(ind) term[ind] = setmetatable({term = term[ind], monitor = m[ind]}, { __call = function(self, ...) self.term(...) self.monitor(...) end }) end set("write") set("setCursorPos")
This will modifie the wright and setCursorPos functions.
Just test it... ;D
#10
Posted 01 March 2013 - 03:12 AM
boudragon, on 28 February 2013 - 11:12 AM, said:
The location is
<minecraft-dir>/saves/<world-name>/computer/<computer-id>
to get the comptuer id type 'id' into the computers console and press enter.
the files in these folders are your programs and you can then edit them with something nicer like Sublime Text 2, which has some awesome support for ComputerCraft added via these awesome people
GravityScore's ComputerCraft Syntaxer and NeverCast's Auto-Lua Selector Thingy (this one is default to Lua, but on one of the last few pages in the first link I describe how you can make it work with GravityScores Plugin)
#11
Posted 01 March 2013 - 05:31 AM
#12
Posted 01 March 2013 - 07:21 AM
But anyway, you'll just have to run that code and it will change the term table.
That means you can put it into it's own file and load it with os.load(), you could start it with shell.run(), or you can put it anywhere in your existing programm, it just has to be run once. (obviously before you want to use it)
#13
Posted 01 March 2013 - 11:14 AM
::Edit:: btw Joker as a beginner NOTHING is basic! LOL! Just meant that the whole monitor thing really isn't even a necessary part of what Im trying to put together...
#14
Posted 01 March 2013 - 03:53 PM
::EDIT::
Ok so for some reason its working fine now. One question I have though. Lets say I do EDIT STARTUP and it loads up whatever is already in the startup file. once I enter it doesnt set the cursor to the right position and when I exit it doesnt clear the screen... how can that be fixed since the problem technically lies within the edit program itself? Also when typing any input it displays what is being typed like this:
If I type the word HELLO it will display : HHEHELHELLHELLO
#15
Posted 02 March 2013 - 08:41 AM
boudragon, on 01 March 2013 - 03:53 PM, said:
simply add this to the end of the code:
set("clear") term.setCursorPos(term.getCursorPos())
#1 Only these 3 functions that are passed to the set() function will work for both monitors. If you need anotherone, just add it
#2 It didn't know the previous cursorposition. The last line of code 3 lines above should fix that...
#16
Posted 02 March 2013 - 09:50 AM
::EDIT::
Ok so I tried it and it didn't seem to fix the issue... its still displaying user input like this:
HHEHELHELLHELLO
and when editing a file it displays but its not really showing an edit screen its just displays what the file contains then writes over what was displayed when I type. And for some reason when I add several print lines instead of displaying them one on top of another it displays all in one line unless I tell it a specific cursor position.
#17
Posted 03 March 2013 - 02:32 AM
To the HHEHELHELL...I had the same thing as long as I didn't have the term.setCursorPos for both monitors. So maybe check if it is typed correctly.
If you still can't find it, just write the exact thing you do when this occurs, because I cannot replicate it.
#18
Posted 03 March 2013 - 02:37 AM
JokerRH, on 03 March 2013 - 02:32 AM, said:
for k,v in pairs( peripheral.getMethods('right') ) do print(v) end
#19
Posted 03 March 2013 - 03:22 AM
TheOriginalBIT, on 03 March 2013 - 02:37 AM, said:
Thanks! So he just has to add a set("setCursorBlink") to the code.
I tried to make it copy all the functions, but there are some that won't work for monitors...
#20
Posted 03 March 2013 - 08:50 AM
::EDIT::
Ok so I found the problem! Turns out my set("set.CursorPos") was typed as set("setCUrsorPos). That tiny mistake made a world of difference! LOL! Now everything seems to be working right. I do have one more question though and I think it may be similar to this question... let's say I have a variable that I want to toggle between "On" and "Off" but I want that variable to remain either "On" or "Off even if the system shuts down... how would I do that? I got it to toggle and display that it toggled but it doesn't seem to store it for future use...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users