Archived

This topic is now archived and is closed to further replies.

SikCiv

Getting a variable name at runtime.

Recommended Posts

When compiling in Debug mode, it keeps the original variable names in the EXE for debug purposes, am I right? If so, say if u had a blitting function that takes a DDraw surface pointer, the destination position, and source rects, but fails during runtime for some reason, maybe because the surface was lost or whatever, how do u tell which surface failed? I was wandering if there is a command that takes a pointer (say a DDraw surface) and dumps the variable name to a string??

Share this post


Link to post
Share on other sites
No, you can''t. It doesn''t work so.
I think you should implement some sort of logging in your programming. It''s all worth it, I promise ;-)
Every time your program want to alert the user about something, just write it down to a file. It will make your debugging much easier.


Share this post


Link to post
Share on other sites
When it comes to logging files I use a couple of methods
For a quick look at variables I use file output all on one line
FILE *fp = fopen("returnstr.txt", "wt"); fputs(pReturnString,fp); fclose(fp); // debug string



As well I have dozens of player action functions that sometimes need debugging. To occassionally track them when there''s a crash, I use a #define to able/disable the file logging. As well I have a variable that that I use to keep the files sorted in order when I take a look at my run-time directory
1001LoadPlayer.txt
1002LoadPlayer.txt
1003LoadPlayer.txt
1004LoadPlayer.txt
1005AnalyzeBalance.txt
1006LaunchAttack.text
1007LaunchAttack.text
1008LaunchAttack.text
1009LaunchAttack.text
1010PlayerUnconscious.txt
...

// #define JTDEBUG 1

int Actor:layerUnconscious()
{
#ifdef JTDEBUG
char show[80];
sprintf(show, "%d%s", numDebug++, "PlayerUnconscious.txt");
FILE *fp = fopen(show, "wt"); fprintf(fp,"Yside\n" ); fclose(fp); // debug string
#endif
status = UNCONSCIOUS;
SpriteNum = PLAYERDOWN;
pAction = Waiting;
}

ZoomBoy
A 2D RPG with skills, weapons, and adventure.
See my character editor, Tile editor and diary at
Check out my web-site

Share this post


Link to post
Share on other sites
Since we're talking about logging functions...

I usually create one error handling function that takes parameters like description, error number, function name and a boolean Fatal variable.
I then print it all to a .log file (sometimes with a time stamp) and if the error is a Fatal one, I notify the user with a MsgBox.

Then I just check if there were any errors in the functions (almost all of them, not the smaller ones though) and call the error handler if there is one.
Just watch out for loops, the log file easily gets flooded, so set a maximum file size and check the log file size before printing out anything.

Of course there are probably better ways to do this (usually assertion) but since I'm still a VB dude...

The best error reports I've seen must be in Unreal Tournament, you get an assertion error and the exact way the functions called eachother, how do they do that?.

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown

Edited by - Spiff on 4/6/00 3:26:34 AM

Share this post


Link to post
Share on other sites
Much of Unreal (and therefore Unreal Tournament too, I''m guessing) is coded in their proprietary language UnrealScript, which is very similar to Java, compiled into bytecode and then executed by the virtual machine. I expect the variable names and function names are left in the bytecode for such debugging purposes. I know that the class definitions are themselves objects, so you can look at a class from within the program

Share this post


Link to post
Share on other sites
Another tip that I have found useful is to write a call stack function (and write it to the file), this, in conjunction with an error logging bit, makes for a powerful tool to use when debugging. An example of some output from my engine:

-->WinMain()
--->CEngine::Start()
---->CDatabase::GetFile("test.dbt")
!- Error occured in CDatabase::GetFile
Name: File not found
Desc: The file passed to the function was either not found or could not be loader
Critical: No
-!
<----CDatabase::GetFile("test.dbt")
<---CEngine::Stop()
<--WinMain()

What I did was have all my classes inherit a IDebug class I wrote, that contained all the functions I needed.

Share this post


Link to post
Share on other sites
noxa: that sounds interesting. you are tracing calls when an error occurs, (at least so do i understand that). how do you do that? do you print all function calls in a file, or only when an error occured?
i think i will implement something like that

Share this post


Link to post
Share on other sites
quote:
Original post by Gromit

Unrealscript is used for ai and other in game actions and responses. Not to code the actual game.


Firstly, I think a lot of the skilled AI guys may take issue at you not considering the AI to be the ''actual game''. Personally I think it is more important than how many polygons you can push around onscreen, but there you go.

However, you are wrong anyway. Here''s an except from their code:

// Texture: An Unreal texture map.
// This is a built-in Unreal class and it shouldn''t be modified.
//=============================================================================
class Texture expands Bitmap
safereplace
intrinsic;

// Subtextures.
var(Texture) texture BumpMap; // Bump map to illuminate this texture with.
var(Texture) texture DetailTexture; // Detail texture to apply.
var(Texture) texture MacroTexture; // Macrotexture to apply, not currently used.

// Surface properties.
var(Texture) float Diffuse; // Diffuse lighting coefficient.
var(Texture) float Specular; // Specular lighting coefficient.
var(Texture) float Alpha; // Alpha.
var(Texture) float DrawScale; // Scaling relative to parent.
var(Texture) float Friction; // Surface friction coefficient, 1.0=none, 0.95=some.
var(Texture) float MipMult; // Mipmap multiplier.

// Sounds.
var() sound FootstepSound; // Footstep sound.
var() sound HitSound; // Sound when the texture is hit with a projectile.

// Surface flags. !!out of date
var bool bInvisible;
var bool bMasked;
var(Surface) bool bTransparent;
var bool bNotSolid;
...etc...

It''s not designed for the end user to modify, but it -is- coded in UnrealScript. And I don''t consider texture maps to be AI. By the look of it, almost all the game is in UnrealScript.

Share this post


Link to post
Share on other sites