Jump to content




Exiting a program


11 replies to this topic

#1 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 21 February 2013 - 10:34 AM

Is there a command to exit a program that brings you back to the command line like terminating? Something like shell.exit(), but not stopping the whole computer.

#2 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 21 February 2013 - 10:39 AM

os.queueEvent("terminate")
os.pullEvent("terminate")


#3 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 21 February 2013 - 10:41 AM

You can also use "return" or "shell.exit()".

#4 NDFJay

  • Members
  • 216 posts
  • LocationLeeds, England

Posted 21 February 2013 - 11:00 AM

adding on to what sammich lord said, if your program is a while loop you can use "break"

#5 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 21 February 2013 - 11:07 AM

Thanks, the os.queueEvent("terminate"), os.pullEvent("terminate") works perfectly for me.

#6 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 22 February 2013 - 03:25 PM

View Postabihoooo, on 21 February 2013 - 11:07 AM, said:

Thanks, the os.queueEvent("terminate"), os.pullEvent("terminate") works perfectly for me.

Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 February 2013 - 03:47 PM

View PostDlcruz129, on 22 February 2013 - 03:25 PM, said:

Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.
Its actually not a bad coding habit. Using error() is actually the bad coding habit. Unfortunately 'error' is one of the easiest ways to do it in CC since we don't have functions such as 'os.exit'.

#8 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 22 February 2013 - 04:18 PM

View PostTheOriginalBIT, on 22 February 2013 - 03:47 PM, said:

View PostDlcruz129, on 22 February 2013 - 03:25 PM, said:

Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.
Its actually not a bad coding habit. Using error() is actually the bad coding habit. Unfortunately 'error' is one of the easiest ways to do it in CC since we don't have functions such as 'os.exit'.
Actually, queuing terminate calls error(). (Look in the bios) so queuing terminate is actually worse than just calling error()

#9 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 22 February 2013 - 09:12 PM

If you return from outside a function, you return from the whole program - because the whole program is actually a single big function.

#10 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 23 February 2013 - 03:05 PM

View Postimmibis, on 22 February 2013 - 09:12 PM, said:

If you return from outside a function, you return from the whole program - because the whole program is actually a single big function.

Interesting, I never knew that.

#11 Lewis.holcombe

  • Members
  • 12 posts

Posted 24 February 2013 - 09:54 AM

In theory can't you go do this

Clear()
Term.setCursorPos(1,1)

#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 24 February 2013 - 10:01 AM

View Postabihoooo, on 21 February 2013 - 10:34 AM, said:

Is there a command to exit a program that brings you back to the command line like terminating? Something like shell.exit(), but not stopping the whole computer.

Has you question actually been answered yet? Mm Oh I see you said os.queueEvent("terminate") works but like people said, it's probably not the best way ... if it's outside a function, use return, inside a function - use a boolean or whatever for it to check if it must end or whatever

View PostLewis.holcombe, on 24 February 2013 - 09:54 AM, said:

In theory can't you go do this

Clear()
Term.setCursorPos(1,1)

Clear() is not a function
You're probably thinking of term.clear() and all that does is clear the screen





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users