how to add parameters to functions invoked from button events?

Posted By: GMorningEstrela

how to add parameters to functions invoked from button events? - 12/11/09 02:54

hi guys. let's say i have inside a panel a button:

button (250, 134, "add1.pcx", "add2.pcx", "add3.pcx", add, NULL, NULL)

and i want my add function to look like this:

add(int x, int y){
return x + y;
}

how do i do something like this? the reason for me asking is because I don't like using global variables and that's how I used to do it. thanks for your replies
Posted By: MrGuest

Re: how to add parameters to functions invoked from button events? - 12/11/09 03:09

heya
Code:
PANEL* pnl_add = {
   button(250, 134, "add1.pcx", "add2.pcx", "add3.pcx", add, NULL, NULL);
   flags = SHOW;
}

int add(var id, PANEL* pnl){
   switch(id){ //choose button
      case 1:
         return(value);
      break; //case 1; add button
   } //switch(id)
} //add(id, pnl)


though you'll need some global variables for the function to know what to add, panel buttons only pass button number and panel through parameters

what exactly are you trying to do?
Posted By: GMorningEstrela

Re: how to add parameters to functions invoked from button events? - 12/11/09 05:04

Hi, thanks for your response. I wrote a poker game and I have a panel button BET that bets a variable amount of money. I used to accomplish this by having a global var that holds this amount. Now, I'm rewriting all my code trying to get rid of global variables as much as possible because I'm going to be combining my code with other similar poker games. What would you suggest the best approach is? Thanks
Posted By: Gordon

Re: how to add parameters to functions invoked from button events? - 12/11/09 22:34

create a structure to hold all the global variables for a game then create one instance of this structure. This will basically give you the concept of a name space from c++ and is how it is implemented in some compilers.
© 2023 lite-C Forums