|
about pan_setbutton`s question
#336658
08/05/10 16:22
08/05/10 16:22
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
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?
Last edited by frankjiang; 08/05/10 16:24.
development 3d game is interesting!
|
|
|
Re: about pan_setbutton`s question
[Re: frankjiang]
#336663
08/05/10 16:48
08/05/10 16:48
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
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 --------------------------------------------------------------------------------
development 3d game is interesting!
|
|
|
Re: about pan_setbutton`s question
[Re: frankjiang]
#336742
08/05/10 22:32
08/05/10 22:32
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! If you wrote the following line like this 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
Hope this helps! Ottawa Ver 7.86.2 Pro and Lite-C
|
|
|
Re: about pan_setbutton`s question
[Re: frankjiang]
#336749
08/05/10 23:07
08/05/10 23:07
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
Serious User
|
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
buttonpro(1) assigns not the functions itself (resp a pointer to the function) but its return value.
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
I <3 LINQ
|
|
|
Re: about pan_setbutton`s question
[Re: FlorianP]
#336764
08/06/10 01:08
08/06/10 01:08
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
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.
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
Last edited by frankjiang; 08/06/10 01:27.
development 3d game is interesting!
|
|
|
Re: about pan_setbutton`s question
[Re: frankjiang]
#336776
08/06/10 07:15
08/06/10 07:15
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
Serious User
|
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
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.
I <3 LINQ
|
|
|
Re: about pan_setbutton`s question
[Re: FlorianP]
#336782
08/06/10 08:38
08/06/10 08:38
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
thanks ,FlorianP how to you know that?
Last edited by frankjiang; 08/06/10 09:17.
development 3d game is interesting!
|
|
|
|