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)
This is a discussion on all-endurant command within the C++ Programming forums, part of the General Programming Boards category; is there a way to make a command usable throughout the whole program(ie. During the whole program, if the user ...
Can you be a little more vague
24bbs.cppCode:if( numeric_limits< byte >::digits != bits_per_byte ) error( "program requires bits_per_byte-bit bytes" );
Still too vague - what exactly are you trying to do? Or are you asking how games save and load?
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 )]();
My best code is written with the delete key.