Need some help

This is a discussion on Need some help within the C++ Programming forums, part of the General Programming Boards category; The program is doing something and I want to write something to it while it's working. Example: I'm in a ...

  1. #1
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18

    Question Need some help

    The program is doing something and I want to write something to it while it's working.
    Example: I'm in a fight (DOS text-game) and I'm loosing. I want to run to an other room, but I can't do it because the command has no any effect while the fight goes on. When I get killed the command to go to an other room is executed and thats a bit too late. Anyone having some ideas how to fix this?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Get it to accept the command while you're in the fight.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    I dont know how to do that. That's why I need help.

  4. #4
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    If I put a cin in the middle of fight code, the fight stops and that is not what I want. I want the fight to continue even when I'm writing and when I press enter, I want it to do the thing I wrote.

  5. #5
    Registered User -Xp-'s Avatar
    Join Date
    Nov 2002
    Posts
    28

    ..."">>>""">>>">>"

    how about (dunno if this works not tested)

    Code:
    while (!getch(key))
    {
        fight stuff
    }
    what u want it to do when u press 'key'
    im not too good on key inputs so slap me if im wrong
    No I DIDN'T steal my name from Misro$ofts OS, it's pure coincidence.

    The lines around my name (-) are only there because i needed a name over the 3 character minimum letter limit

  6. #6
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    Caze slaps -Xp-
    It didn't work. Any more ideas?

  7. #7
    Registered User -Xp-'s Avatar
    Join Date
    Nov 2002
    Posts
    28
    you need to include conio.h, and replace 'key' with the key (may need quotes, etc (i dunno))
    No I DIDN'T steal my name from Misro$ofts OS, it's pure coincidence.

    The lines around my name (-) are only there because i needed a name over the 3 character minimum letter limit

  8. #8
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    getch() doesn't take any parameters. It only works if I leave
    getch() empty, and I have tried that and it didn't work.

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    try getche() with the e. it is a real function.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Umm, I'm not sure if it's standard but you can try using _kbhit() or kbhit() or something, it's a non-blocking function, meaning your game can get on with its life while you don't type anything.
    Code:
    while(theGameShouldBeRunning)
    {
    if(kbhit())
    {
        int char = getchar(); // or something along those lines; BTW, it won't wait for input, 
                                // it'll just read whatever you hit to get kbhit() to set off.
        if(char == 'q')
            break;  //q for QUIT
    }
    }
    That's basically the idea, it might not be standard though, so if your compiler barfs then try rearranging the letters or just give up on it
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21