Page 1 of 1

Handy script to control console debug printing

Posted: Fri Jan 25, 2013 3:24 pm
by Komag
As I'm drawing closer to finishing my dungeon, I realized I wanted to go through and turn off all the debug messages I used to work through the scripts.

I knew it would take a while to hunt them all down, and I knew I would still be making more of them while working on the last couple levels, so I set up the following script to handle it much more neatly:

script entity called pr

Code: Select all

printON = true

function nt(m1,m2,m3,m4)
  if printON then
     if      m2 == nil and m3 == nil and m4 == nil then print(m1)
      elseif m3 == nil and m4 == nil then print(m1,m2)
      elseif m4 == nil then print(m1,m2,m3)
      else   print(m1,m2,m3,m4)
     end
  end
end

pr.nt("Debug texts are ON")
------------------------------------

-- this function and variable are for console printing. If
-- printON is true then all the console debug text will
-- print during play. Turn this to false before final release.

-- In scripts in the dungeon I might have a line like:
-- pr.nt("blah blah blah")
It can handle prints with up to four segments (I've only ever used two), such as:
pr.nt(my_table, variable1.." is not the way", suchTimer.x, suchTimer.y)

I've converted all my "print" to "pr.nt" by doing a big 'ol search and replace in the dungeon.lua, and voila, now it works great, and I can leave them on for the beta-testers and then just turn em off at public release time by editing "printON = true" to "printON = false"

Re: Handy script to control console debug printing

Posted: Fri Jan 25, 2013 3:41 pm
by Neikun
Wait, so people with console activated won't get spammed with messages when playing your mod?

That's so cool!

Re: Handy script to control console debug printing

Posted: Fri Jan 25, 2013 3:50 pm
by Grimfan
This will probably come in very handy for advanced modders who don't have similar scripts already prepared.

As a beginner (and definitely not an advanced modder) I would like to know what a typical debug message looks like and how it is implemented to make the job of testing your dungeon easier? Of course, this might have already been covered somewhere else, so just point me in the right direction if it has.

And I look forward to playing through your dungeon. :)

Re: Handy script to control console debug printing

Posted: Fri Jan 25, 2013 6:43 pm
by Komag
I use them a TON for advanced setups that aren't working right, usually to diagnose and narrow down where the problem is.

If a function needs to call three other functions and I'm getting an unexplained crash, I can print messages from each function to see what gets printed before the crash (when you go back in preview you can see the recent console messages still there).

Or if I just have a lot going and it's hard to keep it all straight in my head, printed updates of the code segments happening in order can help bring clarity.

Sometimes the precise order of things makes a huge difference, but it can be hard to tell what part is really happening next since it all seems simultaneous, even in the code. A door or lever might be getting reset because the "not" was flipping the Boolean after the checking function but before the final timer firing or counter reaching zero or pressure plate deactivating after a teleport or for loop closing or WHATEVER!

Print messages sent to console are a Grimrock puzzle creator's friend! :D