Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: bigace on January 13, 2013, 07:43:59 pm

Title: [XP] Throwing an Error message
Post by: bigace on January 13, 2013, 07:43:59 pm
So I was trying to throw an error message if the developer put in an Input:: I deem unusable and then the program closes. The problem is that the program closes with out throwing the error message.
			raise(SystemExit, "Sorry, but the button inputs B, L, R, UP, DOWN, RIGHT, " + 
"LEFT, F5, 56, F7, F8, or F9 is not allow. " +
"Please choose A, C, X, Y, Z, or SHIFT inputs instead for the scene " +
"changing button.")

I know this code works:
			print("Sorry, but the button inputs B, L, R, UP, DOWN, RIGHT, LEFT, F5, " + 
"56, F7, F8, or F9 is not allow. " +
"Please choose A, C, X, Y, Z, or SHIFT inputs instead for the scene " +
"changing button.")
exit

But I was wondering why the first code doesn't work. Thats all.
Title: Re: [XP] Throwing an Error message
Post by: ThallionDarkshine on January 13, 2013, 09:03:13 pm
Im not quite sure what the problem is with your code, but i think it would work without the first argument.
Title: Re: [XP] Throwing an Error message
Post by: LiTTleDRAgo on January 13, 2013, 09:43:12 pm
Quote from: bigace on January 13, 2013, 07:43:59 pm
Quoteraise(SystemExit, "Sorry, but the button inputs B, L, R, UP, DOWN, RIGHT, " +
            "LEFT, F5, 56, F7, F8, or F9 is not allow. " +
            "Please choose A, C, X, Y, Z, or SHIFT inputs instead for the scene " +
            "changing button.")

Title: Re: [XP] Throwing an Error message
Post by: bigace on January 13, 2013, 09:51:06 pm
I know that, but that doesn't anwser my question. Why does it close without giving a message when you have SystemError in there?
Title: Re: [XP] Throwing an Error message
Post by: ThallionDarkshine on January 13, 2013, 10:08:10 pm
Maybe some types of errors simply force a quit and log the error somewhere.
Title: Re: [XP] Throwing an Error message
Post by: bigace on January 15, 2013, 08:00:47 am
I guess no one knows the answer, if not then I guess we're stuck with ThallionDarkshine answer until then. :(
Title: Re: [XP] Throwing an Error message
Post by: ThallionDarkshine on January 15, 2013, 10:01:12 am
Ill look it up, but its probably something like my idea
Title: Re: [XP] Throwing an Error message
Post by: G_G on January 15, 2013, 08:19:00 pm
A SystemExit exception is when the program is closed via system. AKA Closing it through the Red X button. You can usually catch the exception and do some finalizing code. So if you're making the script throw a SystemExit exception, it's just going to close the game without any warning, as if someone were actually closing the game. Replace "Main" with this snippet and close the game with the Red X. You'll see what I'm talking about.

begin
  # Prepare for transition
  Graphics.freeze
  # Make scene object (title screen)
  $scene = Scene_Title.new
  # Call main method as long as $scene is effective
  while $scene != nil
    $scene.main
  end
  # Fade out
  Graphics.transition(20)
rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
rescue SystemExit
  print "Closed via X"
end
Title: Re: [XP] Throwing an Error message
Post by: bigace on January 15, 2013, 10:24:28 pm
Was my game supposed to freeze? As that's what happened when I placed it in my game.
Title: Re: [XP] Throwing an Error message
Post by: G_G on January 15, 2013, 11:01:19 pm
When I run the game with that script and close the game with the X button, it prints out "Closed via X" You were supposed to have replaced "Main"
"
Title: Re: [XP] Throwing an Error message
Post by: bigace on January 16, 2013, 09:36:09 pm
I did replace Main :<_<: , but my computer was being retarded so the game froze then crashed. I just tested it again a second ago and it did everything you just said. Thank you for the information.