This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Displaying user input on a monitor.
Started by boudragon, 28 February 2013 - 07:58 AMPosted 28 February 2013 - 08:58 AM
Ok so first let me start with yes I am new to this forum, LUA and ComputerCraft. Apologizes ahead of time for being a noob! :)/> I do have some knowledge of Quick Basic but obviously it's not quite the same. Now for my question… Ive set up a simple password program that asks for the user to input a word and if it matches the variable then it unlocks the system… simple stuff. The problem I have is trying to get it to display the input as the user is typing it in the computer on the monitor. The best I can get is after they type in the password and hit enter it displays what they typed on the monitor. How can I get the monitor to display what the user is typing AS they are typing it on the monitor as well as the computer? Thanx in advance!
Posted 28 February 2013 - 09:07 AM
Split into new topic.
Posted 28 February 2013 - 10:34 AM
You need to redirect the monitor.
term.redirect(peripheral.wrap("top"))
local yourInput = read()
Posted 28 February 2013 - 10:40 AM
the read function cannot display on two monitors at the same time. So you'll have to write your own like this:
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 :)/>
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 :)/>
Posted 28 February 2013 - 10:43 AM
Do you have ANY code you can show us so we can help you further?
Posted 28 February 2013 - 11:04 AM
Do you have ANY code you can show us so we can help you further?
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.
Posted 28 February 2013 - 11:07 AM
I'm going to guess you would want to capture their keystrokes using an event in a loop, then return "yes" or "no" whenever they hit enter. Printing the keys as they type of course.Do you have ANY code you can show us so we can help you further?
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.
Posted 28 February 2013 - 11:12 AM
Ok I managed to write a portion of the program to text to give you guys an idea of the noob I am LOL! Again… VERY sloppy but keep in mind Im also doing all this just in MC. Also thanx so far for all the help!
::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?
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?
Posted 01 March 2013 - 02:55 AM
::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?
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
Posted 01 March 2013 - 03:12 AM
If you save the file you do have access to that on your computer (or the server's files if you can get to them).Ok I managed to write a portion of the program to text to give you guys an idea of the noob I am LOL! Again… VERY sloppy but keep in mind Im also doing all this just in MC. Also thanx so far for all the help!
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)
Posted 01 March 2013 - 05:31 AM
Hey thanx JokerRH but I have NO IDEA what to do with what you posted. Do I add it as its own file? add to the startup file? Why couldnt this have been programmed in QB Id have been done by now LOL! Funny thing is this is just a BASIC thing I still got a lot more to program! Grrr
Posted 01 March 2013 - 07:21 AM
Metatables are not that basic, so everything is normal if you don't understand them as a beginner…:D/>
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)
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)
Posted 01 March 2013 - 11:14 AM
So just say add those lines to the beginning of the startup file and all should be good to go?
::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…
::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…
Posted 01 March 2013 - 03:53 PM
Ok so Joker it works GREAT… I think the only issue I have now is the spacing on the monitor is off. Its actually making it to where if there is text in line 1 and 2 on the computer it shows up as line 1 and 3 on the monitor. Other than that this is PERFECT!
::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
::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
Posted 02 March 2013 - 08:41 AM
once I enter it doesnt set the cursor to the right position and when I exit it doesnt clear the screen…
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 :D/>
#2 It didn't know the previous cursorposition. The last line of code 3 lines above should fix that…
Posted 02 March 2013 - 09:50 AM
Ok I will try it out as soon as I can and get back to you :)/> Also when it comes to entering and exiting a program my screen needs to always clear and reset the cursor to (1,1). keeps it clean… even though my coding is sloppy! LOL!
::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.
::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.
Posted 03 March 2013 - 02:32 AM
I don't think there is a setCursorBlink for monitors, therefor you cannot make it blink in the editor on both devices.
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.
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.
Posted 03 March 2013 - 02:37 AM
There is indeed setCursorBlink for monitors….. http://puu.sh/2aMxtI don't think there is a setCursorBlink for monitors, therefor you cannot make it blink in the editor on both devices.
for k,v in pairs( peripheral.getMethods('right') ) do
print(v)
end
Posted 03 March 2013 - 03:22 AM
There is indeed setCursorBlink for monitors….. http://puu.sh/2aMxt
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…:(/>
Posted 03 March 2013 - 08:50 AM
:P/> Ok… if you could post what my code should look like now I can double check and see if it's right so far and also see where I may have went wrong cause some things still aren't working quite right. This way I can see if it's what I added or maybe an error I made typing in the code you've helped me with so far.
::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…
::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…
Posted 05 March 2013 - 09:12 AM
Did I lose my tech support? :(/>
Posted 05 March 2013 - 09:50 AM
Of course not :D/>Did I lose my tech support? :(/>
Had to do quite a lot for school this weekend :P/>
Anyway, you'll have to write it to a file:
var = yourBoolVar and 1 or 0 --If yourBoolVar == true then var = 1 else var = 0 end
file = fs.open("path/name", "wb") --I used write binary for this example as you seem to have a boolean value
file.write(var)
file.close()
And to reload:
file = fs.open("path/name", "rb")
var = file.read()
file.close()
yourBoolVar = (var == 1) or false --if var == 1 then yourBoolVar = true else yourBoolVar = false end
This is an example for a boolean variable. You could of course use "w" and "r" so you don't have to mess around with binary mode, but I thought it would fit here :)/>
Note: Neither of these two examples is tested, if it somehow doesn't work try to replace the if statements with the content that is currently commented out (that is the longer version), maybe I derped a little with that but I don't think I did…hopefully :D/>
Posted 05 March 2013 - 10:09 AM
Well the thing is Im trying to make the variables as "Online" and "Offline" for the purpose of using the same variables as text later to show whether each "Power Bay" is on or off… so using a number may not be exactly the best way to do it… also is it better to use a variable file to write to / read from rather than putting this sort of variable in the same file or no?
Posted 05 March 2013 - 10:13 AM
Didn't fully understood your last sentence, but if you want to save it as strings it is even easier.
Simply open the file in normal write ("w") or read ("r") mode and you can write strings into the file instead of numbers.
Simply open the file in normal write ("w") or read ("r") mode and you can write strings into the file instead of numbers.
Posted 05 March 2013 - 10:22 AM
Ok so lets say bay1 = "Offline" and later on down the code it asks the user to make a choice. They then choose option 1 to toggle bay 1… so all I would have to do is something like this?
is that accurate?
bay1 = "Offline"
file = fs.open("path/name", "bay1")
file.write("Online")
file.close()
is that accurate?
Posted 05 March 2013 - 10:32 AM
fs.open([path to file], [mode])
mode can be
"w" to write (will delete what used to be in that file/creates new one),
"r" to read
"a" to write at the end of the file (won't delete file)
"wb" write binary (numbers),
"rb" read binary (numbers)
#1 to write your variable to the file
#2 to relad it
#3 This is usefull if your computer will be restarted and you want to reload it. If the variable is just in another API you can define it like this
If you do that you should be able to access it from any other API just by typing [your api].bay1 (as you can access a function)
mode can be
"w" to write (will delete what used to be in that file/creates new one),
"r" to read
"a" to write at the end of the file (won't delete file)
"wb" write binary (numbers),
"rb" read binary (numbers)
#1 to write your variable to the file
file = fs.open([path], "w")
file.write(bay1)
file.close()
#2 to relad it
file = fs.open([path], "r")
bay1 = file.readLine()
file.close()
#3 This is usefull if your computer will be restarted and you want to reload it. If the variable is just in another API you can define it like this
function whatever()
end
bay1 = ""
function ...()
end
If you do that you should be able to access it from any other API just by typing [your api].bay1 (as you can access a function)
Posted 05 March 2013 - 10:56 AM
Ok im trying it out… I keep getting Unsupported mode… I cant for the life of me figure out what Im doing wrong…
Posted 05 March 2013 - 11:10 AM
Modes are what I typed in above. If you write anything else there it will give you an unsupported mode error(as you tested it :P/>/>)
So make sure you chosed them correctly (they have to be a charakter ("w" for example, not w)
The path should be obvious :)/>
So make sure you chosed them correctly (they have to be a charakter ("w" for example, not w)
The path should be obvious :)/>
Posted 05 March 2013 - 11:56 AM
Ok so I got is… sort of… and thank god I was doing it on a test computer! I got it to open a file and write in it HOWEVER… thats ALL that was written! LOL! It deleted EVERYTHING else that I had programmed! So Im on the right track but what I dont get is where am I suppose to tell it a specific variable to alter rather than eliminating the whole file and putting in what I told it to?
Im thinking maybe a working example might really help my better understand it… If you can maybe whip up a small program that I can get and look at?
Im thinking maybe a working example might really help my better understand it… If you can maybe whip up a small program that I can get and look at?
Posted 06 March 2013 - 04:45 AM
I got it to open a file and write in it HOWEVER… thats ALL that was written!
Well, what did you expect it to write in there. If you only tell him to write your bay1 in the file it will only write that in it :D/>
So maybe the path isn't that obvious :P/>
The path is the path to the file you want to work with, not the path that refers to your api (of course that works, but you already noticed the downside).
Edit:
So Im on the right track but what I dont get is where am I suppose to tell it a specific variable to alter rather than eliminating the whole file and putting in what I told it to?
After the second reading I don't think you understood what this will do. It will NOT modify a variable in a running code or a file, instead it will write the variable into it's own file (as a string). That's why I had a saving and a loading part…
Posted 06 March 2013 - 05:46 AM
Yeah I figured that out LOL! I think the easiest way would be to have a var1 and var2 file with an On or Off string in each. I actually had it working… I think but had to take several steps back… (as I made a small mistake and ended up ruining ALL the work I did so far) :(/> On the plus side Im improving my skills and re-wrote most of what I lost already and re-wrote it better than before. So hopefully by the end of today I will have some results to share!
Posted 06 March 2013 - 06:09 AM
You can write them in one file, too.
file.writeLine(var1)
file.writeLine(var2)
will write var1 into the file and then var2.
to read it out again do
var1 = file.readLine()
var2 = file.readLine()
If you open the file it sets a pointer that points to the first line. Everytime you do a writeLine/readLine it increments the pointer line by 1.
That also means you cannot read out line 5 without having read line 1-4!
file.writeLine(var1)
file.writeLine(var2)
will write var1 into the file and then var2.
to read it out again do
var1 = file.readLine()
var2 = file.readLine()
If you open the file it sets a pointer that points to the first line. Everytime you do a writeLine/readLine it increments the pointer line by 1.
That also means you cannot read out line 5 without having read line 1-4!
Posted 06 March 2013 - 07:36 AM
I think to keep it simple I will just use 2 different files. My luck Id end up writing over the wrong line… or in the case today where I ruined EVERYTHING… lol! The crappy part was right before I did it… I said to myself "You know… maybe I should back all this up…" Famous last words right?
Posted 07 March 2013 - 06:42 AM
OK! So… after having to start all over… and re-write EVERYTHING… I managed to get it all working! Just one FINAL question. The monitor updates just fine for everything… but when I am in the command prompt and type say "edit FILE"… it pulls up the edit screen with data on both the terminal and the monitor but the monitor looks kinda funky. Any idea how to fix that?
Posted 07 March 2013 - 07:22 AM
OK! So… after having to start all over… and re-write EVERYTHING… I managed to get it all working! Just one FINAL question. The monitor updates just fine for everything… but when I am in the command prompt and type say "edit FILE"… it pulls up the edit screen with data on both the terminal and the monitor but the monitor looks kinda funky. Any idea how to fix that?
Kinda funny? What do you mean kinda funny? Explain or post a screenie lol
Maybe it's because the monitor is bigger than 51x19
Posted 07 March 2013 - 07:29 AM
No its like it doesnt know how to "update" the screen right… like it will show HHH instead of just H… or if I type it adds more than what I typed… scrolling makes it even worse lol! Doing just a line or two doesnt make the error… but mostly a huge program + scrolling = disaster…
::EDIT::
If you type a line longer than the monitor can handle the monitor doesnt scroll like the terminal would…
::EDIT::
If you type a line longer than the monitor can handle the monitor doesnt scroll like the terminal would…
Posted 07 March 2013 - 08:15 AM
the read function cannot display on two monitors at the same time. So you'll have to write your own like this: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 :)/>
Check the code: term.setCursoros(x, y)
Posted 07 March 2013 - 08:21 AM
His original code had a typo but I already fixed that… again everything works fine but editing doesn't update the display on the monitor properly
Posted 07 March 2013 - 09:22 AM
@ZudoHackz: This is not the code he currently uses (I think), a little bit further down there should be anotherone :D/>
@boudragon: The monitor won't be able to scroll if you don't have a set("scroll"), but I'm sure that that would cause some problems, because when the terminal is already "full" the monitor isn't (or the other way if you have a small monitor). You can try it, but I don't know what will happen. (at least it will not delete your code :D/>). Maybe you just have some blank lines on the monitor.#
Edit: It works just fine. Just for clearance I will write the (tested) code as it should be atm here:
#1 The scroll is described above
#2 clearLine should fix your error
#3 make sure you don't run the programm twice. If you do it will write everything twice/3x/4x/…
I didn't find any error with this version :P/>
Edit2: If you have a golden monitor you can of course add set("setTextColor") and set("setBackgroundColor"). That works if you change them manually, but somehow it won't work with the edit programm :(/> (That means edit won't change the color)
Anyone here that knows why?
Edit3: If you use this you probably don't want the getInput() function I wrote in the beginning, as it might cause some problems as well
@boudragon: The monitor won't be able to scroll if you don't have a set("scroll"), but I'm sure that that would cause some problems, because when the terminal is already "full" the monitor isn't (or the other way if you have a small monitor). You can try it, but I don't know what will happen. (at least it will not delete your code :D/>). Maybe you just have some blank lines on the monitor.#
Edit: It works just fine. Just for clearance I will write the (tested) code as it should be atm here:
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")
set("clear")
set("setCursorBlink")
set("clearLine")
set("scroll")
term.setCursorPos(term.getCursorPos())
#1 The scroll is described above
#2 clearLine should fix your error
#3 make sure you don't run the programm twice. If you do it will write everything twice/3x/4x/…
I didn't find any error with this version :P/>
Edit2: If you have a golden monitor you can of course add set("setTextColor") and set("setBackgroundColor"). That works if you change them manually, but somehow it won't work with the edit programm :(/> (That means edit won't change the color)
Anyone here that knows why?
Edit3: If you use this you probably don't want the getInput() function I wrote in the beginning, as it might cause some problems as well
Posted 07 March 2013 - 10:18 AM
Considering the program is simply startup and the rest of my setup runs off independent files (other programs) this works flawlessly! So far that is ;-) I only did a simple test on it… it's about to get the full work-up now…
::EDIT::
Just ran it through a full cycle and its perfect other than like you said… running startup twice on the same boot sequence (without a system shutdown or reboot) causes a ripple effect. How would that be solved if possible?
::EDIT::
Just ran it through a full cycle and its perfect other than like you said… running startup twice on the same boot sequence (without a system shutdown or reboot) causes a ripple effect. How would that be solved if possible?
Posted 07 March 2013 - 10:31 AM
How would that be solved if possible?
function set(ind)
if type(term[ind]) ~= "function" then return end
term[ind] = setmetatable({term = term[ind], monitor = m[ind]}, {
__call = function(self, ...)
self.term(...)
self.monitor(...)
end
})
end
This additional line will detect if term[ind] is a function. If it is already modified it is a table and will not be set twicePosted 07 March 2013 - 11:04 AM
Absolutely amazing thank you! JokerRH super kudos for sticking with me through all this! Once I get in contact with my server admin to enable the ability to use pastebin I will upload some stuff for you to check out! I have learned quite a bit! Thanx again!
Posted 07 March 2013 - 02:31 PM
Ok… so… pastebin isn't working and the server admin wont be on for a while so… looks like I get to type all this out! well… here it goes!
This is the startup file. Make sure you have a monitor attached to the top. It's made for a 4 long by 2 tall monitor. You can change this in the code. NOTE: In order for this to work you MUST have a memcheck file on a disk and placed in a drive attached to the system before running (memcheck needs to have the number 640 in the first line). Also, there must be a lock file (you can use any password protection lock you want as long as the file is named "lock") and a btsm file with the first line of text saying "–BTSM Header". Let me know what you think! And if you'd like the other files to get the full effect just tell me and I will get to work on re-writing the code.
WARNING - Just in case it was missed… you CAN NOT terminate this once it has begun! If you want to re-add the terminate function just remove line 26 of the code.
::EDIT::
I know the spacing for the BouTech Corp. sign looks off but it should be correct… for some reason adding code on the forums altered the spacing…
This is the startup file. Make sure you have a monitor attached to the top. It's made for a 4 long by 2 tall monitor. You can change this in the code. NOTE: In order for this to work you MUST have a memcheck file on a disk and placed in a drive attached to the system before running (memcheck needs to have the number 640 in the first line). Also, there must be a lock file (you can use any password protection lock you want as long as the file is named "lock") and a btsm file with the first line of text saying "–BTSM Header". Let me know what you think! And if you'd like the other files to get the full effect just tell me and I will get to work on re-writing the code.
mon = peripheral.wrap("top")
momc = "disk/memcheck"
memcf = fs.exists(memc) and io.open(memc, "r") or nil
btsmc = "btsm"
btsmcf = fs.exists(btsmc) and io.open(btsmc, "r") or nil
--THANK YOU to JokerRH for this next part!
function set(ind)
if type(term[ind]) ~= "function" then return end
term[ind] = setmetatable({term = term[ind], monitor = mon[ind]}, {
__call = function(self, ...)
self.term(...)
self.monitor(...)
end
})
end
set("write")
set("setCursorPos")
set("print")
set("setCursorBlink")
set("clear")
set("clearLine")
set("scroll")
term.setCursorPos(term.getCursorPos())
term.clear()
term.setCursorPos(1,1)
os.pullEvent = os.pullEventRaw
print"|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|"
print"| BouTech Corporation |"
print"|-------------------------------------|"
print""
print"BTC OS version 1.2"
sleep(2)
term.setCursorPos(1,6)
print "Memory Check"
sleep(1)
term.setCursorPos(13,6)
print"."
sleep(1)
term.setCursorPos(14,6)
sleep(1)
print"."
term.setCursorPos(15,6)
print"."
sleep(1)
if (memcf and memcf:read()=="640") then
term.setCursorPos(17,6)
print"640Kb OK!"
sleep(2)
if (btsmcf and btsmcf:read()=="--BTSM Header") then
term.setCursorPos(1,8)
print"::WARNING::"
sleep(1)
print"Authorized access only!"
sleep(1)
print"CyberPunk Security now loading..."
sleep(3)
cpsc = fs.exists("lock")
if cpsc == true then
shell.run("lock")
else
term.setCursorPos(1,11)
print"System corrupt! Running system restore..."
sleep(3)
file = fs.exists("disk/restore/sysrest")
if file == true then
shell.run("disk/restore/sysrest")
else
print"System restore file not found on disk."
print"System rebooting..."
sleep(3)
os.reboot()
end
end
else
term.setCursorPos(1,8)
print"System corrupt! Running system restore..."
sleep(3)
file = fs.exists("disk/restore/sysrest")
if file == true then
shell.run("disk/restore/sysrest")
else
print"System restore file not found on disk."
print"System rebooting..."
sleep(3)
os.reboot()
end
end
else
term.setCursorPos(17,6)
print"Memory Test Failed!"
sleep(2)
os.reboot()
end
WARNING - Just in case it was missed… you CAN NOT terminate this once it has begun! If you want to re-add the terminate function just remove line 26 of the code.
::EDIT::
I know the spacing for the BouTech Corp. sign looks off but it should be correct… for some reason adding code on the forums altered the spacing…
Posted 07 March 2013 - 10:07 PM
Looks cool! just 3 things I noticed while I was reading your code:
#1 You don't need a set("print"), print is a function that uses write
#2 insetead of
But none of these 3 points will make your programm instable. Nice!
#1 You don't need a set("print"), print is a function that uses write
#2 insetead of
cpsc = fs.exists("lock")
if cpsc == true then
you can simply write
if fs.exists("lock") then
and #3: If your system is corrupted and you don't have a disk with your restore files it will run forever and always notice that are files missing.But none of these 3 points will make your programm instable. Nice!
Posted 07 March 2013 - 10:15 PM
EDIT: Better yet, I would use a comment :P/>
Posted 08 March 2013 - 02:06 AM
Thanx Joker :)/> I will clean it up a bit! I have it run forever on purpose… cause either way if the system is corrupt its going to need a system restore. If you dont have the sysrest file you can always just break the terminal then copy the backup files back onto it. And Suicidal… yeah I could use comments to help me remember but generally when it comes to ANYTHING computer related I usually do good on the remembering department! LOL