26 posts
Posted 15 January 2013 - 01:42 PM
Hello, I am wondering if there us any "structure" to build off of for making a text based OS. All I need it to do it when you type a word in, it does a specific action. It needs to be expandable.
What I have started with is horrible but gives kind of what I want:
term.clear()
term.setCursorPos(1, 1)
print("NovOS 0.1")
local cmd = ""
while cmd ~= "help" do
term.write("Nov: ")
cmd = read
end
print("Command List: Blah Blah Blah")
This prompts the user with "Nov: " like I want it to whenever someone goes to enter a command. I'd like it to say when it doesn't understand a command, also.
When I type "help", it does what I want but stops the program and opens the console.
Thanks.
7508 posts
Location
Australia
Posted 15 January 2013 - 01:53 PM
I suggest making the change to the while loop if you don't want it to exit… make it infinite loop…
while true do
cmd = read()
if cmd == "help" then
elseif cmd == "something else" then
else
print( "Unkown command: "..cmd )
end
end
26 posts
Posted 15 January 2013 - 01:59 PM
Thanks, that seems about right. How cna I make it prompt "Nov: " After every like? Like so when you type "help" it would actually show "Nov: help" and "Nov: Unknown Command"? I nkew the code was simple, and I was close. I tired about everything but that. Thanks for the help! I believe I can keep expanding elseif statements as long as I need, correct?
7508 posts
Location
Australia
Posted 15 January 2013 - 02:00 PM
while true do
write("Nov: ")
.....
print( "Nov: Unknown command" )
Edited on 15 January 2013 - 01:00 PM
26 posts
Posted 15 January 2013 - 02:11 PM
Thanks again. I should really take a few hours and really learn lua. It's a bit tough remembering it all!
7508 posts
Location
Australia
Posted 15 January 2013 - 02:15 PM
Thanks again. I should really take a few hours and really learn lua. It's a bit tough remembering it all!
No problems… Work through
this should defs help! And also (don't take this the wrong way) but maybe put the OS aside and start with something simpler and work your way back up to the OS… or, have a file thats the os, and another testing file, where you work on only one feature, without all the other code getting in the way…
Edited on 15 January 2013 - 01:16 PM
26 posts
Posted 15 January 2013 - 02:21 PM
Yeah, I'm only working on a basic OS to control a few things like lights and such. I'm having an issue…I added the
"term.clear()
term.setCursorPos(1, 1)
print("NovOS 1.4r1")"
while true do
cmd = read()
if cmd == "help" then
elseif cmd == "something else" then
else
print( "Unkown command: "..cmd )
end
end
and replaced your "something else"s and when the pc reboots, its locked at NovOS 1.4r1. I can't type, terminate, or do anything. I have no idea why.
Edit: It also shows the block texture as "off"
Sorry for the sloppy post, I'm a bit rushed.
7508 posts
Location
Australia
Posted 15 January 2013 - 02:29 PM
use [
code][
/code] tags makes it look nicer
use ctrl + r to reboot the computer and see it it does it again… the program should wait for you to press enter on the read()
this code should work perfectly… make sure its this
term.clear()
term.setCursorPos(1,1)
print("NovOS 1.4r1")
while true do
write( "Nov: " )
local cmd = read()
if cmd == "help" then
elseif cmd == "something" then
else
print( "Unknown command: "..cmd )
end
end
26 posts
Posted 17 January 2013 - 03:09 AM
You can't do anything! No buttons work or anything.
term.clear()
term.setCursorPos(1, 1)
print("NovOS 1.4r1")
while true do
cmd = read
if cmd == "help" then
print("help is on the way!")
elseif cmd == "lock" then
print("Computer Locked")
end
end
I know the lock doesn't work, I was temporary, and I made a new PC and was able to get everything working…werid.
EDIT: Oh wait…I forgot "else". Perhaps that's what screwed it over.
7508 posts
Location
Australia
Posted 17 January 2013 - 03:38 AM
You can't do anything! No buttons work or anything.
term.clear()
term.setCursorPos(1, 1)
print("NovOS 1.4r1")
while true do
cmd = read
if cmd == "help" then
print("help is on the way!")
elseif cmd == "lock" then
print("Computer Locked")
end
end
I know the lock doesn't work, I was temporary, and I made a new PC and was able to get everything working…werid.
EDIT: Oh wait…I forgot "else". Perhaps that's what screwed it over.
No missing the else isn't the problem
missing the () at the end of read is… you are wanting to call read, not store its reference… add () to the end of read and it should be good :)/>