I want to add a feature to my game engine where I can change different variables that control in-game things while the engine is still running from a console window.

I have designed the engine in C++, and because of its compile-time nature, I don't think it's possible to change inner-working variables during run-time. I have looked at python extensions for C++, but I do not know if that will be sufficient to change values while the program is running.

How do I edit runtime variables within a custom C++ game engine?


Of course you can change variables during run time, your engine is doing in constantly, otherwise it wouldn't be an interactive! It'll be a lot of work to dynamically list variables, since you'd have to create some kind of preprocessor to parse the code (essentially recreating C#s reflection).

  • Create callbacks for each variable you want to be able to modify
  • Add them to a dictionary with their name as the key.
  • Your terminal just looks for the key and parses the input to convert it to the correct type, then sets the variable.
  • You'll also need events for when variables change, to reload the systems that use those variables
| improve this answer | |
  • \$\begingroup\$ Wow... its amazing the things that you dont think of until someone else explains it. So I could just add the hot key to the switch-case statement within the game loop and have it accept the input as a std::cin input and then edit differing variables accordingly. Thank you for your help. \$\endgroup\$ – xec86 Nov 10 '16 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.