about pan_setbutton`s question

Posted By: frankjiang

about pan_setbutton`s question - 08/05/10 16:22

Code:
function buttonpro(var i){
	switch (i)
	{
		case 0:
			gv=2;	
		break;
		case 1:
			gv=3;
		break;
	}
}	

pan_setbutton(gp[0],0,1, // set a new push button for quitting the game
     			10,10,gb[1],gb[2],gb[3],NULL,buttonpro(1),NULL,NULL);


buttonpro(1) is error,i want set function parameter for buttonpro.is it impossibility?
Posted By: frankjiang

Re: about pan_setbutton`s question - 08/05/10 16:48

if then can`t set function parameter ,i write code like this :
--------------------------------------------------------------------------------
function buttonpro(var i){
var x = mouse_pos.x;
var y = mouse_pos.y;
if(x>=0&&x<=40){
if(y>=0&&y<=20){//btn1
gv = 20;
}
if(y>=40&&y<=60){//btn2
gv = 60;
}
}
}
pan_setbutton(gp[0],0,1,0,0,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL); //btn1
pan_setbutton(gp[0],0,1,0,40,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL);//btn2
--------------------------------------------------------------------------------
Posted By: Ottawa

Re: about pan_setbutton`s question - 08/05/10 22:32

Hi!

If you wrote the following line like this
Quote:

pan_setbutton(gp[0],0,1, // set a new push button for quitting the game
10,10,gb[1],gb[2],gb[3],NULL,buttonpro(1),NULL,NULL);

Then you should write it like

pan_setbutton(gp[0],0,1, 10,10,gb[1],gb[2],gb[3],NULL,buttonpro(1),NULL,NULL); // set a new push button for quitting the game
Posted By: FlorianP

Re: about pan_setbutton`s question - 08/05/10 23:07

buttonpro(1) assigns not the functions itself (resp a pointer to the function) but its return value.

Code:
pan_setbutton(gp[0],0,1,	10,10,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL);



You can only use it without the bracket and you cannot pass any arguments to the function urself.
Anyway the button functions gets - the number of the button in the panel - automatically passed as first argument and this might be waht u need/want
Posted By: frankjiang

Re: about pan_setbutton`s question - 08/06/10 01:08

thanks ,guys.

did you have any good idea to design it?
pan_setbutton(gp[0],0,1,10,10,gb[1],gb[2],gb[3],NULL,buttonpro(1),NULL,NULL);

is it possiable to pass any arguments for buttonpro?
if not,did you have any good ideas to do that?
...............................................................................
why i want to do write code like this:buttonpro(1)?
my point of view:
in code files,just used a few of functions to do any things like butt on events.
one panel objest has 3 buttons events ,so you must be to creat 3 functions . i think it is not better than just used one functions .
if there are much more function`s name ,it`s so hard to mangaged them.

well,just want to find a good way to managed my codes. it is so import.



ok show my idea,just used one function to control their events,and different for your mouse postion.
Code:
var gv;
function buttonpro(var i){
   var x = mouse_pos.x;
   var y = mouse_pos.y;
   if(gp[0].flag=SHOW){   //gp[0] is a panel object
      if(x>=0&&x<=40){
          if(y>=0&&y<=20){//btn1
            gv = 20;
          }
          if(y>=40&&y<=60){//btn2
            gv = 60;
          }
       } 
    }
}
pan_setbutton(gp[0],0,1,0,0,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL); //btn1
pan_setbutton(gp[0],0,1,0,40,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL);//btn2


Posted By: FlorianP

Re: about pan_setbutton`s question - 08/06/10 07:15


Code:
var gv;
function buttonpro(var i, PANEL* p)
{
   if (p == my_firstPanel)
   {
     //only if this specific panel is clicked
     if (i == 1)
     {
        //first button of the panel
     }
     if (i== 2)
     ....
   }
   if (p == my_secondPanel)
   {
   .....
   }
}
pan_setbutton(gp[0],0,1,0,0,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL); //btn1
pan_setbutton(gp[0],0,1,0,40,gb[1],gb[2],gb[3],NULL,buttonpro,NULL,NULL);//btn2



The function gets the number of the button and a pointer to the panel passed automatically.
Posted By: frankjiang

Re: about pan_setbutton`s question - 08/06/10 08:38

thanks ,FlorianP
how to you know that?
Posted By: Widi

Re: about pan_setbutton`s question - 08/06/10 11:50

From the manual wink
© 2023 lite-C Forums