Hello I'm trying to pass a key array to a function in another class and its not working. Can anyone explain to me essentially what the key array is? Is it an array of char? Well anyways here is my code I'm getting errors please help. Thanks


HERE IS MY CALL IN THE MAIN FUNCTION

bullet.gunDirection(leftOrRight, key[], screen, position);

HERE IS MY FUNCTION WITHIN THE CLASS

void Projectile::gunDirection(char previousDirection, char currentDirection, BITMAP* screen, Motion position){
     
    //Points to be used for drawing the player 
    int X2 = position.getXLocal() + 15;
	int Y2 = position.getYLocal() - 15;
	int X3 = position.getXLocal() + 30;
	int Y3 = position.getYLocal() - 30;
	int Y4 = position.getYLocal() - 35;
 
    //If the user pressed the left arrow key then
    //the player will point the gun to the left
	if(currentDirection[KEY_LEFT]){
        line(screen,X2,Y3,position.getXLocal(),Y3,makecol(255, 0, 0));
        previousDirection = KEY_LEFT;
    }
    
    //If the user pressed the right arrow key then
    //the player will point the gun to the right
	else if(currentDirection[KEY_RIGHT]){
        line(screen,X2,Y3,X3,Y3,makecol(255, 0, 0)); 
        previousDirection = KEY_RIGHT;
    }
    
    //If the user didn't press anything and the previous
    //arrow selected was left then we keep pointing the
    //gun to the left    
	else if(previousDirection == KEY_LEFT)
	    line(screen,X2,Y3,position.getXLocal(),Y3,makecol(255, 0, 0));
	    
	//Otherwise we point the gun to the right    
    else
        line(screen,X2,Y3,X3,Y3,makecol(255, 0, 0));
	    
}

Hello

the key is a character array(or consider it as array of flags i.e. having value true or false). and is used like :

if(key[KEY_UP])y--;

which means Whenever up arrow key is pressed the KEY_UP offset of key array is set to true.

Your function call must be giving compilation error because

bullet.gunDirection(leftOrRight, key[], screen, position);

//should be called as

bullet.gunDirection(leftOrRight, key[KEY_RIGHT], screen, position);

but this is not the solution, u should change function prototype to

void Projectile::gunDirection(char previousDirection, BITMAP* screen, Motion position);

and inside function use key array instead of currentDirection.

And 2 more points,
1. Passing screen as argument does not make sense to me
2. Download a pdf documentation of allegro, it will be quite useful

Vinayak
Happy New Year

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.