is there a way to make a command usable throughout the whole program(ie. During the whole program, if the user types in save, it will save their game)
is there a way to make a command usable throughout the whole program(ie. During the whole program, if the user types in save, it will save their game)
Can you be a little more vague
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
for example a game. say the user is walking and has to quit their game. how could they save whenever they want, anytime during the whole proggy.
Still too vague - what exactly are you trying to do? Or are you asking how games save and load?
gg
I want the person to be able to save at any time in the game that they want at all. Would I have to have an if command for every time the computer asks for input?
>(ie. During the whole program, if the user types in save, it will save their game)
You could do this any number of ways. An easy solution would be to save the current game any time the quit option is selected (be sure to confirm that the user wants to save). Another option is to maintain a second thread that handles "any time" input and acts accordingly. I could make better suggestions if I knew the design of your game, if it is based on text commands like a MUD then all you need to do is create a save command. If it is an action game then you should probably offer an option to save at regular intervals or have a menu option or a hotkey like Ctrl+S that can be accessed quickly without pausing the game or that sets the game to a pause state.
>Would I have to have an if command for every time the computer asks for input?
A command table of function pointers would be better. That way you can simply say something like:
Instead of a long string of conditionals. Then all you have to do is add a save command to the table and you're done.Code:command[get_index ( cmd )]();
-Prelude
My best code is written with the delete key.