Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calin Leafshade on Fri 17/08/2012 18:42:44

Title: Check if game is runnig under the debugger
Post by: Calin Leafshade on Fri 17/08/2012 18:42:44
Is there a way to see if AGS is running under the debugger? I know that you can check if its in debug mode but thats not the same thing.
Title: Re: Check if game is runnig under the debugger
Post by: Crimson Wizard on Fri 17/08/2012 19:32:45
It is possible for plugin to do this by calling IAGSEngine::IsRunningUnderDebugger() method.

I do not see any way to know this from game script.
Title: Re: Check if game is runnig under the debugger
Post by: Calin Leafshade on Fri 17/08/2012 19:37:25
A funny quirk of the engine is that, when running under the debugger, the working directory of the game is the root source directory, not the compiled directory.

So i've found that you can try and open the acsetup.cfg file for reading and if it fails then you must be under the debugger.
Title: Re: Check if game is runnig under the debugger
Post by: Crimson Wizard on Fri 17/08/2012 20:35:59
I am curious why do you need this.

If you think that may come handy in certain situations we may plan a script function for checking this?
On other hand, there's already RickJ's request to allow getting command line arguments from script, and engine connects to debugger when it receives --enabledebugger parameter in cmdline.
Title: Re: Check if game is runnig under the debugger
Post by: Khris on Fri 17/08/2012 20:37:42
Could this work maybe?

Code (ags) Select
bool debugger;

// in game_start
#ifdef DEBUG
  debugger = true;
#endif
Title: Re: Check if game is runnig under the debugger
Post by: Crimson Wizard on Fri 17/08/2012 20:43:20
Quote from: Khris on Fri 17/08/2012 20:37:42
Could this work maybe?

Code (ags) Select
bool debugger;

// in game_start
#ifdef DEBUG
  debugger = true;
#endif


Alas, this tests if Game's Debug mode is on, it doesn't test if the game is run under debugger (from AGS Editor).
Title: Re: Check if game is runnig under the debugger
Post by: Calin Leafshade on Fri 17/08/2012 21:26:34
Quote from: Crimson Wizard on Fri 17/08/2012 20:35:59
I am curious why do you need this.

Tis a convoluted reason but i will indulge you

I am making a game in Lua and it does quite a lot of things that could be considered "Meta Engine". For instance it iterates through all my inventory items and builds a script for me where i can easily edit properties of the items without doing a lot of typing. Also I have map files that are generated as actual lua script and automatically deposited in the lscripts folder which is only accessible when running under the debugger. Alot of this stuff is done automatically but will fail if I give someone a compiled build to test. Now instead of manually disabling those things everytime i want to give someone a build I thought it would be nice if I could detect it on the fly.

Hence my question.

If youre super curious a map file looks like this:

Code (lua) Select

-- Generated At 05:07:39
Map2 =
{
Name = "Map2",
Width = 32,
Height = 32,
Tileset = 1,
Layers = 1,
Walkable =
  {
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {1,1,0,0,1,1,1,1,1,1,1,1,1,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
},
Data =
  {
    {
      {3,3,18,25,3,3,3,3,3,3,3,32,30,42,3,3,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,3,3,3,3,3,29,30,42,3,3,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,3,3,3,3,32,30,30,42,3,3,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,3,3,3,3,32,30,30,42,3,3,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,3,3,3,3,29,30,30,42,3,3,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,3,3,3,29,30,30,30,42,3,29,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,28,34,34,34,29,30,30,30,30,41,29,30,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,29,30,30,30,30,30,30,30,30,30,30,30,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,19,19,19,30,30,30,30,30,30,30,30,30,30,30,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,19,19,19,30,30,30,30,30,30,30,30,30,30,30,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,31,30,30,30,30,30,30,35,39,39,39,39,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,31,30,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,31,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,18,25,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,6,12,20,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {6,12,20,3,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {12,20,3,3,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {20,3,3,3,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,3,3,3,3,32,30,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,3,3,3,3,3,31,30,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {3,3,3,3,3,3,3,3,31,30,30,36,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    },
  }
}
setmetatable(Map2, { __index = Map } )
Map2.__index = Map
Maps["Map2"] = Map2


This is generated by my map editor which is part of the game. Then when i next run the game it now has a new global object "Map2" which can be edited and resaved if need be.
Title: Re: Check if game is runnig under the debugger
Post by: Crimson Wizard on Fri 17/08/2012 21:52:18
Since you are using Lua plugin, I guess you may ask Denzil Quixode to add another function callable from either AGS script or lua script, that wraps IAGSEngine::IsRunningUnderDebugger()?