views:

166

answers:

5

I was thinking of doing this with C++, basically from an external editor or something the programmer can say: MyClass::dude = "hello" where 'dude' is a static integer in 'MyClass'.

What the program does at runtime is it partitions the input to MyClass :: dude = "hello" and finds the class called 'MyClass' and assigns the dude variable in it as "hello".

The idea behind it is for it to act as a sort of a runtime debugger.

Is this safe/sane?

A: 

The description isn't very clear, can you clarify? Is this something that should happen while the program is running? Or would it run this using the variable?

One of the differences between C++ and Java is that the class names aren't really used in the executable program (unless it was specifically compiled for debugging). So there's no way a program can make a running C++ program find specifically a variable in that program.

Either way, without making the "debugged" program be compiled with enough information and functionality to do this, it's not really practical, but it's not clear what you're trying to do.

I'm also not clear what this has to do with inheritance (the title of your question).

Uri
+2  A: 

Your typical debugger can already do this for all basic types.

Assigning a char string value is a bit more involved since it requires allocating memory for the actual string and assigning a pointer to it to the variable.

Hans
+3  A: 

Yes, this is a typical tool used during development to help fine-tune games. It's not so often something you type in as much as a screen where you can adjust variables on the fly with a controller (that changes some class variable under the hood), but for pc games, there isn't a reason why you couldn't type in something, especially if it's text. You would, of course, need to program your own system where a class notifies some part of your engine of it's name and how to get at some of its variables.

Jim Buck
I once wrote generic system for tweaking all kinds of values on the fly. It was used in couple of games and was really helpful. But to my surprise, generic tuning systems are not that common. Many shops just make tools for some special cases like particles.Now I am working in a big project, where there is no such advanced tool for modifying pretty much anything that is declared modifiable. Also in my personal hobby projects, I real miss such tool. Maybe there are some tools out there in the wild already. I mean something that can just be dropped in to existing game engine.
Virne
When I actually tried to search such tool, I found this:http://www.antisphere.com/Wiki/tools:anttweakbar Looks promising on the first glimpse.
Virne
When I did an intership at a game company we also had something like this. There was a console and you could change lots and lots of stuff. Very helpful, especially for the tester.
sjmulder
I hate to sound like some kind of old fart here, but I implemented such a system in my first game industry job in 1996 for a PlayStation 1 game (Rally Cross). I was responsible for the physics, and it was using simulation methods, so having a real-time variable tuner was absolutely necessary.
Jim Buck
+1  A: 

Your best bet it to use something like Boost::python, and integrate a real scripting language. This is a whole lot less work than building your own mini-language. For instance, it will already know how to deal with problem statements like "MyClass::dude = "hello" where 'dude' is a static integer in 'MyClass'."

MSalters
A: 

although not a very elegant solution i sometimes wrap up static versions of variables which i require to change on the fly through the debugger in order to tweak stuff, then just comment out the corresponding #define when done with it, particularly helpful if load times are long and its just a few vars you need to tweak in order to test something. but then again for something like this you should probably consider data files that can be reloaded at runtime

Stowelly