About functions..

This is a discussion on About functions.. within the C++ Programming forums, part of the General Programming Boards category; How do you do two functions at one time? if you need to know, im using borland C++ dos compiler ...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    About functions..

    How do you do two functions at one time?

    if you need to know, im using borland C++ dos compiler mkay?

    Soo.....If you need to know more golly gosh just ask me

    How do you do two functions at once?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    The first answer would be to use threading (running two functions seperately at the same time), but since you're using a borland dos compiler, I'm not sure if it's possible. The simple answer is that you can't, and you should redesign your program to round robin the functions you need to run at "the same time", allowing them to keep their state between each run.. (static variables, or a repository of structures... or just a buffer of raw memory...). What are you writing?

    ...and now a more knowledgeable member will come and tell you a simple clean way of doing this
    .sect signature

  3. #3
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    err.....english please! im only 12 years old
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  4. #4
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    ok, I'll give you an example:

    Code:
    int function1(int arg, int *state)
    {
         switch(*state)
         {
         case 1:
              printf("state 1!: %d\n", arg);
              break;
         case 2:
              printf("state 2!: %d\n", arg*2);
              *state = -1;
              break;
         };
    
         *state++;
          return 0; 
    };
    it's a bit messy, but you can see that between each time the function runs it will "remember" the way it was the last time it ran, and do different work depending on where it is.
    .sect signature

  5. #5
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Ok....I dont remember well but someone told me an easy way, it was like:

    ___sync___();

    it had sync in it: i remember because i started to laugh when i say that word: can you fill in the blank?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  6. #6
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Please gimme something that works!!!




    I want something that can, let say this:



    #include <iostream.h>
    #include <conio.h>

    void right()
    {
    //blah blah makes the char move to the right
    }

    void shoot()
    {
    // yadaya makes the char shoot a little bullet
    }

    int main()
    {
    while(1)
    {
    //whatever i want here
    char action = getch();
    if (action == 77)
    {
    //Ok, this is what i want to know, how to make him able to
    //walk right and shoot at the same time

    }
    if (action == 27)
    break;
    }
    return 0;
    }





    without the function that allows you to do two functions at once, when you shoot you have to wait till it finishes shooting then be allowed to move and i dont want that. please help me
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  7. #7
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    In this case you need something a little more complex than a function that causes the guy to shoot a bullet and the function that causes the guy to move. Here's the solution I would use:

    I would create a particle system for the game you're writing, something with a structure like this:

    Code:
    class particle {
    public:
       particle();
       ~particle();
       int setvars(int xp, int yp, int xf, int yf, int t);
       int tick(void);
    
    private:
       int xpos, ypos;
       int xforce, yforce;
       int type;
    };
    it's a bit ugly and simplistic, but it would probably do the trick. the setvars function would set each of the variables in the class, and the tick() function would do the motion for the particle for a single tick. example:

    Code:
    int particle::tick(void)
    {
       /* handle differences in motion system for different particles */
       switch(this->type)
       {
           case BULLET:
                this->x += this->xf;
                this->y += this->yf;
                break;
       };
    
    };
    if this is a bit more complex than you want, you might try posting your question to the c programming board (and get it in plainer structures..), or to the game programming board and ask how to get a guy moving and shooting at once.
    .sect signature

  8. #8
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Well if i understanded all that i would be happy but im not old enough to understand or i mean not good enough but i'll try your other suggestions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM

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