Thread: catch the same objet with stand alone and with parameter

  1. #1
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002

    catch the same objet with stand alone and with parameter

    Hi friend ,
    It's just my first thread .
    i write a code for a text adventure game.
    but i have some problem with look command
    i want it use with both way a stand alone look and with object
    let me clear,
    when i give command
    then it displays the object such as watch,chair
    >look watch then info abt watch
    just like
    printf("u currently looking a watch,chair,fan).
    >look watch
    printf("Its 5:45 now")
    its possible to use look with both ways?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >>its possible to use look with both ways?
    Yes, if you code it that way You just need to recognise the extra text the user types and act accordingly.

    If you're talking about game programming, we have a forum specifically for that topic, I suggest you post questions like this in there. This forum is for C questions.

    Welcome to
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    This is easy. You make your parser basicly just rip the first word from the string. You compare that word with the list of commands to see if the command is valid. If it isn't a valid command, then either dispose of the whole string and tell the user that the command was invalid, or make it have some default action like talking or something. (Since this is single player, that wouldn't benifit you, so just go for option one.)

    From there, you pass the rest of the string along to the function/command itself. If the string you pass is empty, then you just use the standard no-argument version. If it contains something, you chop it up into arguments and deal accordingly.
    word = parse_input( input )
    if( (command = get_command( word )) != INVALID_COMMAND )
        do_command( command, input+strlen(word) );
        do_invalid( );
    Or you could do it all in a single step:

    if( (command = get_command((word = parse_input( input )))) != INVALID_COMMAND )

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed