Debugging using ag7_debug

This forum is for all those who are or want to create content for the Realms of Trinity world.
AGhost_7
Posts: 2574

Debugging using ag7_debug

Post#1 » Mon Nov 10, 2014 5:48 pm

The ag7_debug file contains a bunch of functions that I like to use for debugging problems that I run into. If you have access to the RoT campaign scripts, it should already be included in the campaign folder, otherwise you can get it here.

The function that you're going to use most of the time is the Debug() function, which simply prints out text in lime green. The debug print will always find its way to your combat log, no real need to give it a valid oPC target.

The basic idea with debugging is to inspect your variables as your code runs. You can then figure out what is wrong with your code relatively easily. Here's an example script which is an item script that executes when you activate (using the custom item property) the item:

Code: Select all

void main()
{
   object oPC = OBJECT_SELF;
   int nMod = GetAbilityModifier(ABILITY_CONSTITUTION,oPC);
   if(nMod > 10)
   {
      effect eHeal = EffectHeal(100);
      ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal,oPC);
   }
}


This script is supposed to heal you for 100 HP if you have a constitution modifier above 10, unfortunately it doesn't do anything. Variables that are most likely to cause the problems would be nMod and eHeal. So adding prints:

Code: Select all

#include "ag7_debug"
void main()
{
   object oPC = OBJECT_SELF;
   int nMod = GetAbilityModifier(ABILITY_CONSTITUTION,oPC);
   Debug("Con modifier " + IntToString(nMod));
   if(nMod > 10)
   {
      effect eHeal = EffectHeal(100);
      
      int bEValid = GetIsEffectValid(eHeal);
      Debug("Effect is valid? " + BoolToString(bEValid));
      
      ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal,oPC);
   }
}


After that, you should notice that the nMod variable is actually returning 0, every single time. In this case, since the function has exhibited proper behavior in the past we can rule it out as being the issue, instead the problem must lie in what we are feeding it. Using that line of thought, its easy to reach the conclusion that the problem is the oPC variable, and upon testing the name you should be able to confirm that. The problem was that OBJECT_SELF in this context is the module object (basically, "the game"), and you need to use the GetItemActivator() to retrieve the player character that activated the item instead.

Extra tips

SetTitle and AddTitle are useful for debugging functions which are executed in several events. Helped a great deal when I did some work on the AI. Simply set the title(e.g., SetTitle("On-Hit")) at the beginning of each event and place your prints in your shared function.

Once you're done debugging, simply comment out the #include "ag7_debug" and it won't compile until you take out all prints (which is nice if you don't want people seeing that on production).

Return to “Content Contributor's Corner”

Who is online

Users browsing this forum: No registered users and 2 guests

cron