224 posts
Location
Auckland, New Zealand
Posted 25 January 2013 - 07:31 PM
Hello, I have a question.
What is the code to exit a program and return to the shell
I tried using shell.exit() - Nothing happens
I tried os.pullEvent("terminate") - The terminal froze
I am currently working on a GUI / UI / OS - Or whatever you want to call it :)/>
You can find my program here: - Its still in development
http://pastebin.com/4rAzgmCzIf you scroll down to line 104 you will see were I put the os.pullEvent("terminate")
Thanks, AnthonyD98
144 posts
Location
Wellington, New Zealand
Posted 25 January 2013 - 07:42 PM
Try using error(). You can also simulate someone pressing CTRL + T by using os.queueEvent("terminate").
EDIT: Also, most of the code in your menu isn't necessary. Try using something like this to draw your menu:
local s = 1
local menuOptions = {"Programs", "Options", "Exit", "Reboot", "Shutdown"}
for i = 1, #menuOptions do
if s == i then
print("[>"..menuOptions[i].."<]")
else
print("[ "..menuOptions[i].." ]")
end
end
224 posts
Location
Auckland, New Zealand
Posted 25 January 2013 - 07:47 PM
Try using error(). You can also simulate someone pressing CTRL + T by using os.queueEvent("terminate").
Thank you the error() worked.
+1 to you
1054 posts
Posted 25 January 2013 - 07:52 PM
A proper way to exit out of the body of the program is simply using "return". But if you have a complex structure, error() would indeed do just fine. It could only interfere with some wrappers for your program in very specific (and rare) circumstances.
224 posts
Location
Auckland, New Zealand
Posted 25 January 2013 - 07:53 PM
A proper way to exit out of the body of the program is simply using "return". But if you have a complex structure, error() would indeed do just fine. It could only interfere with some wrappers for your program in very specific (and rare) circumstances.
I will keep this in mind, thank you.
224 posts
Location
Auckland, New Zealand
Posted 25 January 2013 - 07:59 PM
I know its unrelated to this question but do you guys know how I could set the default selection to 'programs' instead of 'shutdown' ?
224 posts
Location
Auckland, New Zealand
Posted 25 January 2013 - 08:03 PM
Try using error(). You can also simulate someone pressing CTRL + T by using os.queueEvent("terminate").
EDIT: Also, most of the code in your menu isn't necessary. Try using something like this to draw your menu:
local s = 1
local menuOptions = {"Programs", "Options", "Exit", "Reboot", "Shutdown"}
for i = 1, #menuOptions do
if s == i then
print("[>"..menuOptions[i].."<]")
else
print("[ "..menuOptions[i].." ]")
end
end
I would prefer to use the method I am currently using as that is what I am used to.
I really don't mind writing extra lines of code.
758 posts
Location
Budapest, Hungary
Posted 25 January 2013 - 10:09 PM
The problem is you are running selected() a dozen times before any key can affect "s". And "s" is 5. So
local w,h = term.getSize()
local s = 5 -- should be 1
local mainY = 5
local titleY = 1
local maintitleY = 3
Why is it 5 now anyways?
144 posts
Location
Wellington, New Zealand
Posted 25 January 2013 - 11:11 PM
The problem is you are running selected() a dozen times before any key can affect "s". And "s" is 5. So
local w,h = term.getSize()
local s = 5 -- should be 1
local mainY = 5
local titleY = 1
local maintitleY = 3
Why is it 5 now anyways?
This snippet could also be a problem (Part of the main while loop):
elseif s == 5 then
os.shutdown()
758 posts
Location
Budapest, Hungary
Posted 25 January 2013 - 11:27 PM
This snippet could also be a problem (Part of the main while loop):
elseif s == 5 then
os.shutdown()
Yup, it shuts down the computer when you move the selection over Shutdown instantly.
BTW
Elseif counts as a block ending
I mean this is much more readable
if key == keys.down then
s = s+1
if s >= 5 then s = 5 end
selected()
elseif key == keys.up then
s = s-1
if s <= 1 then s = 1 end
selected()
elseif key == keys.enter then
if s == 1 then
os.run("prog")
selected()
elseif s == 2 then
os.run("options")
selected()
elseif s == 3 then
os.pullEvent("terminate")
selected()
elseif s == 4 then
os.reboot()
selected()
elseif s == 5 then
os.shutdown()
end
end
224 posts
Location
Auckland, New Zealand
Posted 26 January 2013 - 11:36 AM
Okay i've made some changes to my code:
You can find the latest version here:
http://pastebin.com/qLwwRbtnAnd 'local s = 5' is now 'local s = 1'
I appreciate all the help you guys are giving me.
I am now making the suggested changes to my code. :)/>
Also I am looking for someone to help me in the process of making my program mouse based aswell as keyboard based - e.g. ( keyboard version of program for non-adv computers & mouse version of program for adv computers )
224 posts
Location
Auckland, New Zealand
Posted 26 January 2013 - 11:46 AM
I have Implemented LBPHacker's more 'readable' version of my code into the program which saves alot of space.
Also there are now colours in the menu
SelectGUI Build #006:
http://pastebin.com/z19FzBbDI have a new question now:
Is anybody willing to help develop SelectGUI further?
1029 posts
Location
Missouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension
Posted 26 January 2013 - 07:18 PM
I have Implemented LBPHacker's more 'readable' version of my code into the program which saves alot of space.
Also there are now colours in the menu
SelectGUI Build #006:
http://pastebin.com/z19FzBbDI have a new question now:
Is anybody willing to help develop SelectGUI further?
SURE
*combines with iHomeOS*
Your program is crap now!
LOL, just kidding.
Also, instead of doing
"shell.run("prog") ;
Copy all your code in prog, and at the begining of the app, do
function prog()
(paste prog's code here)
end
Then, replace shell.run('prog') ; with
"prog()"
This will make it so you only have to upload one file to pastebin.
604 posts
Location
Spring Hill, Fl
Posted 27 January 2013 - 02:33 AM
You could also use:
shell.run("shutdown")
--or
shell.run("reboot")
--or
shell.run("shell")
1+ me if this worked also!
1054 posts
Posted 27 January 2013 - 03:38 AM
You could also use:
shell.run("shutdown")
--or
shell.run("reboot")
--or
shell.run("shell")
1+ me if this worked also!
How is that even remotely helpful? :P/> He's already using os.shutdown() and os.reboot().
224 posts
Location
Auckland, New Zealand
Posted 27 January 2013 - 07:05 PM
I have Implemented LBPHacker's more 'readable' version of my code into the program which saves alot of space.
Also there are now colours in the menu
SelectGUI Build #006:
http://pastebin.com/z19FzBbDI have a new question now:
Is anybody willing to help develop SelectGUI further?
SURE
*combines with iHomeOS*
Your program is crap now!
LOL, just kidding.
Also, instead of doing
"shell.run("prog") ;
Copy all your code in prog, and at the begining of the app, do
function prog()
(paste prog's code here)
end
Then, replace shell.run('prog') ; with
"prog()"
This will make it so you only have to upload one file to pastebin.
Thank you, It will make Things ALOT eaiser :)/> +1 to you
224 posts
Location
Auckland, New Zealand
Posted 28 January 2013 - 01:57 PM
Try using error(). You can also simulate someone pressing CTRL + T by using os.queueEvent("terminate").
EDIT: Also, most of the code in your menu isn't necessary. Try using something like this to draw your menu:
local s = 1
local menuOptions = {"Programs", "Options", "Exit", "Reboot", "Shutdown"}
for i = 1, #menuOptions do
if s == i then
print("[>"..menuOptions[i].."<]")
else
print("[ "..menuOptions[i].." ]")
end
end
I now understand that it is a better idea to use the code above instead of my own bloated code.
Thank you! I am now rewriting my entire OS which will now be much more economic in terms of size.
EDIT: Now why do I need selected() ?