Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Debugging RGSS?

Status
Not open for further replies.
Does anyone know if there are any good RGSS debugging tools out there?
I'm currently experiencing a myriad of errors with my current script and i have been reduced to making message boxes pop up all the time as the script runs in order to findout how far its getting before entering a never ending loop and its taking me forever!

Are the any tools or do i just have to live with it! :S

Thanks!
 

ccoa

Member

Not that I know of.

I use logging to do debugging, it's a lot easier than using prints, and more useful for data that needs to be checked every update or other iteration.

I just put this in main:

Code:
  $logging = true
  if $logging
    $logfile = File.new("logs.txt", 'w')
  end

And this as a new function:

Code:
def log(obj)
  if $logging
    $logfile.print(obj.to_s + "\n")
  end
end

And then just use the log method everywhere. The good part is by turing $logging to false, you don't even have to hunt down and delete all the logging statements! ^_^
 
You can also use this console output script:
Code:
[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#669900]# Console [/COLOR][/FONT]
[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#669900]# This module works much like the Logging module, only instead of saving to a [/COLOR][/FONT]
[COLOR=#669900]# file, output goes to a debugging window. The window only shows up in Debug [/COLOR][/FONT]
[COLOR=#669900]# mode, so launching it from RMXP it will show up, but it won't when run from [/COLOR][/FONT]
[COLOR=#669900]# Game.exe. [/COLOR][/FONT]
[COLOR=#669900]# To use the console, simply call Console::setup() from your Main script, then [/COLOR][/FONT]
[COLOR=#669900]# use echo(string) from any other script you want, like you would print(). [/COLOR][/FONT]
[COLOR=#669900]# [/COLOR][/FONT]
[COLOR=#669900]# The Console allows for quick access to information without having to open a log [/COLOR][/FONT]
[COLOR=#669900]# and without bringing up a message window that halts progress, so it's perfect [/COLOR][/FONT]
[COLOR=#669900]# [/COLOR][COLOR=#0000aa]for[/COLOR][COLOR=#669900] having to track changes in a loop with many iterations. My own tests show [/COLOR][/FONT]
[COLOR=#669900]# no lag, so it should be all good. [/COLOR][/FONT]
[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#0000aa]module[/COLOR] Console [/FONT]
attr_reader    :bufferHandle [/FONT]
 
GENERIC_READ                  = 0x80000000 [/FONT]
GENERIC_WRITE                 = 0x40000000 [/FONT]
FILE_SHARE_READ              = 0x00000001 [/FONT]
FILE_SHARE_WRITE             = 0x00000002     [/FONT]
 
CONSOLE_TEXTMODE_BUFFER   = 0x00000001 [/FONT]
 
[COLOR=#0000aa]def[/COLOR] Console::AllocConsole [/FONT]
  return @apiAllocConsole.call [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
 
[COLOR=#0000aa]def[/COLOR] Console::CreateConsoleScreenBuffer(dwDesiredAccess,dwShareMode,dwFlags) [/FONT]
  return @apiCreateConsoleScreenBuffer.call(dwDesiredAccess,dwShareMode,nil,dwFlags,nil) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
 
[COLOR=#0000aa]def[/COLOR] Console::WriteConsole(lpBuffer) [/FONT]
  hFile = @bufferHandle [/FONT]
  return @apiWriteConsole.call(hFile,lpBuffer,lpBuffer.size,0,0) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
 
[COLOR=#0000aa]def[/COLOR] Console::SetConsoleActiveScreenBuffer(hScreenBuffer) [/FONT]
  return @apiSetConsoleActiveScreenBuffer.call(hScreenBuffer) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
 
 [COLOR=#0000aa]def[/COLOR] Console::SetConsoleTitle(title) [/FONT]
   return @apiSetConsoleTitle.call(title) [/FONT]
 [COLOR=#0000aa]end[/COLOR] [/FONT]
 
[COLOR=#0000aa]def[/COLOR] self.setup [/FONT]
  unless $DEBUG [/FONT]
    return [/FONT]
  [COLOR=#0000aa]end[/COLOR] [/FONT]
  @apiAllocConsole = Win32API.new([COLOR=#800080]"kernel32","AllocConsole","","l"[/COLOR]) [/FONT]
  @apiCreateConsoleScreenBuffer = Win32API.new([COLOR=#800080]"kernel32","CreateConsoleScreenBuffer",['l','l','p','l','p'],"l"[/COLOR]) [/FONT]
  @apiSetConsoleActiveScreenBuffer = Win32API.new([COLOR=#800080]"kernel32","SetConsoleActiveScreenBuffer","l","s"[/COLOR]) [/FONT]
  @apiWriteConsole = Win32API.new([COLOR=#800080]"kernel32","WriteConsole","lpnnn","S"[/COLOR]) [/FONT]
  @apiSetConsoleTitle = Win32API.new([COLOR=#800080]"kernel32","SetConsoleTitle","p","s"[/COLOR]) [/FONT]
 
  access = (GENERIC_READ | GENERIC_WRITE) [/FONT]
  sharemode = (FILE_SHARE_READ | FILE_SHARE_WRITE) [/FONT]
 
  returnCode = AllocConsole() [/FONT]
  @bufferHandle = CreateConsoleScreenBuffer(access,sharemode,CONSOLE_TEXTMODE_BUFFER) [/FONT]
 
  f = File.open([COLOR=#800080]"Game.ini"[/COLOR]) [/FONT]
  lines = f.readlines() [/FONT]
  s = lines[3] [/FONT]
  len = s.size [/FONT]
  title = (s[6,len - 7]) [/FONT]
 
  SetConsoleTitle([/FONT][COLOR=#800080]"Debug Console -- #{title}") [/COLOR][/FONT]
  echo [/FONT][COLOR=#800080]"#{title} Output Window\n" [/COLOR][/FONT]
  echo [COLOR=#800080]"-------------------------------\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"If you are seeing this window, you are running\n"[/COLOR] [/FONT]
  echo [/FONT][COLOR=#800080]"#{title} in Debug Mode. This means\n" [/COLOR][/FONT]
  echo [COLOR=#800080]"that you're either playing a Debug Version, or\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"you are playing from within RPG Maker XP.\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"Closing this window will close the game. If \n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"you want to get rid of this window, run the\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"program from the Shell, or download a Release\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"version.\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"Gameplay will be paused while the console has\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"focus. To resume playing, switch to the Game\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"Window.\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"-------------------------------\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"Debug Ouput:\n"[/COLOR] [/FONT]
  echo [COLOR=#800080]"-------------------------------\n\n"[/COLOR] [/FONT]
  SetConsoleActiveScreenBuffer(@bufferHandle) [/FONT]
[COLOR=#0000aa]end[/COLOR]   [/FONT]
 
[COLOR=#0000aa]def[/COLOR] self.get_input [/FONT]
  [COLOR=#0000aa]loop[/COLOR] do [/FONT]
    poo = $stdin [/FONT]
    [COLOR=#0000aa]if[/COLOR] poo[poo.size - 1] == [COLOR=#800080]"\n"[/COLOR] [/FONT]
      break [/FONT]
    [COLOR=#0000aa]end[/COLOR] [/FONT]
  [COLOR=#0000aa]end[/COLOR] [/FONT]
  echo poo [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
 
[COLOR=#0000aa]module[/COLOR] Kernel [/FONT]
[COLOR=#0000aa]def[/COLOR] echo(string) [/FONT]
  unless $DEBUG [/FONT]
    return [/FONT]
  [COLOR=#0000aa]end[/COLOR] [/FONT]
  Console::WriteConsole(string) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]end[/COLOR][/FONT]
 
Cheers should be a big help, i found that problem but theres sure to be more!
(I made a search function for a linked list but forgot to take into account there might not be any items ON the list! :) )

Edit: You can make this resolved if you want now! All my problems are solved because IT WORKS!!! (I was beginning to give up hope :)
 
This topic has been resolved. If Eivien or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top