Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 10:32
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 604 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
how to add parameters to functions invoked from button events? #301493
12/11/09 02:54
12/11/09 02:54
Joined: Jul 2008
Posts: 3
G
GMorningEstrela Offline OP
Guest
GMorningEstrela  Offline OP
Guest
G

Joined: Jul 2008
Posts: 3
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

Re: how to add parameters to functions invoked from button events? [Re: GMorningEstrela] #301494
12/11/09 03:09
12/11/09 03:09
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
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?

Re: how to add parameters to functions invoked from button events? [Re: MrGuest] #301500
12/11/09 05:04
12/11/09 05:04
Joined: Jul 2008
Posts: 3
G
GMorningEstrela Offline OP
Guest
GMorningEstrela  Offline OP
Guest
G

Joined: Jul 2008
Posts: 3
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

Re: how to add parameters to functions invoked from button events? [Re: GMorningEstrela] #301608
12/11/09 22:34
12/11/09 22:34
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
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.


Our new web site:Westmarch Studios

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1