I'm creating a debug menu, and I want to be able to show a lot of information (variables) on that menu. This information will come from a lot of classes (instances).

How can I show a lot of information from a lot of classes in my debug menu? How can I get access to all the variables of the instances of the classes that I need information from?

  • \$\begingroup\$ You show information in your debug menu by retrieving the data you want from the classes you want to include. For example, you could override the ToString() method in your class and have it return a string of the values you're interested in. Is that the kind of information you're looking for? This question is pretty vague. (And likely a better fit for Stackoverflow since I don't see any gamedev related content here). \$\endgroup\$
    – House
    Commented Jul 20, 2013 at 16:23
  • \$\begingroup\$ Kind of. The ToString would be an idea, although I'm wondering if that's the way to go. With 'information' I mean variables (edited the question). And as I have to show this information on certain places in my menu, I need seperate variables rather than a string. Maybe the question is indeed better fit for SO indeed. \$\endgroup\$
    – Basaa
    Commented Jul 20, 2013 at 16:26

1 Answer 1


What you want to do is homogenize the interface to that information, so that the debug menu itself need only deal with a single concrete API to get information concerning what it needs to display. Your first step, thus, is to ask yourself "what information do I need?"

At a bare minimum, I would expect a debug menu to display key-value pairs: the name of a property or field and it's corresponding value. Both can be represented as strings, because you're so far only talking about displaying that data. Additionally, you probably want each collection of key-value pairs for a particular object instance to be grouped with the rest of the fields for that object, so you'd want an overall container to represent the key-value pairs for a specific object. Perhaps

class field_debug_info {
  string name;
  string value;

class object_debug_info {
   string name;
   array<field_debug_info> fields;

With these types, you can construct your debug menu from a list of object_debug_info objects by iterating through each one, adding a section for the object and then adding sections for each field.

debug_menu::debug_menu (array<object_debug_info> objects) {
  foreach (object in objects) {
    // For each object, add a line with the object's name.
    add_line("{0}", object.name);

    foreach (field in object.fields) {
      // For each field of that object, add a line with the field data.
      add_line("  {0}: {1}", field.name, field.value);

The constructor above would let you create a debug_menu from a list of object debug information. Implementing add_line (particularly with that C#-style string formatting) is left as a task for the reader. Also note that the above is all pseudo-code.

Now that you've accomplished that (and you can test that by manually creating the debug information objects you send to that constructor to start with), you need to get the information from the classes themselves. Because you are using Java, you can use the built-in reflection features to take any object instance and query it for all it fields and their values. You can then transfer that data into your object_debug_info structures (in fact, you could eschew your own object_debug_info structures entirely and just use the Java reflection API's types if you wanted, and didn't need to add any additional data in the future).

The final part of the solution is to write the code that actually iterates all the live object in the game you want to inspect. There's nothing special or magical here: if you want to inspect all character objects in the game when you open a debug menu, have your game collect and send the list of characters to the code that opens the debug menu, and so on.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .