Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,758 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
button function parameters? #252893
02/21/09 06:17
02/21/09 06:17
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
i have a set of buttons and i want each one to call the same function with a different parameter but it gives me the error, too many parameters. I am hoping that im just typing something wrong but i can't find it anywhere.

heres the code, well at least as much as i need help on.

Code:
 	button ( 325, 300, easy_roll, easy_norm, easy_roll, difficulty(1), NULL, NULL);
	button ( 325, 350, medium_roll, medium_norm, medium_roll, difficulty(2), NULL, NULL);
	button ( 325, 400, hard_roll, hard_norm, hard_roll, difficulty(3), NULL, NULL);
	button ( 325, 450, impossible_roll, impossible_norm, impossible_roll, difficulty(4), NULL, NULL);

function difficulty(var diff)
{
	start_pan.visible = OFF;
	if ( diff == 1)
	{
		computer_speed = 2;
		ball_speed = 1;
	}
	if ( diff == 2)
	{
		computer_speed = 4;
		ball_speed = 2;
	}
	if ( diff == 3)
	{
		computer_speed = 6;
		ball_speed = 3;
	}
	if ( diff == 4)
	{
		computer_speed = 10;
		ball_speed = 5;
	}
	players_func();
}


i know i can define a different function for all of them but this way would be easier for me.

Re: button function parameters? [Re: halfpint] #252901
02/21/09 09:14
02/21/09 09:14
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
You cannot pass arguments/parameters to a function when calling it from a button.
But what you can do is the following (writing this from the top of my head so no guarantee that it will work):
Code:
function set_difficulty(button_number, panel)
{
  if(button_number == 1)
  {
    // easy
  }
  if(button_number == 2)
  ...
}

// in your button do this (e.g.)
button ( 325, 300, easy_roll, easy_norm, easy_roll, set_difficulty, NULL, NULL);


Btw: are you using c-script or lite-c?

Re: button function parameters? [Re: Xarthor] #252903
02/21/09 09:39
02/21/09 09:39
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
c-script
So the button_number variable is default and it starts at 1 and continues in whatever order I assigned them in the panel right?
Also is there anything I have to do for the panel parameter or does it just tag along?

And thanks I did not think of this being an option.

Re: button function parameters? [Re: halfpint] #252906
02/21/09 10:22
02/21/09 10:22
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Yes as far as I remember button_number starts with 1, but you can check it out easily with some test function.

The panel parameter is just another parameter, you don't have to use it, but you can use it and identify a panel based on that parameter I think.

Re: button function parameters? [Re: Xarthor] #252935
02/21/09 15:11
02/21/09 15:11
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
Please halfpint, tell me if this worked, because there's nothing on manual about button_number...

i know the pan_setbmap and stuff but the actually button_xx ..

Re: button function parameters? [Re: halfpint] #252986
02/21/09 22:52
02/21/09 22:52
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
To my surprise I actually did it first try, works perfect thanks a lot. Heres the source for the button and function.

Code:
 
        button ( 325, 300, easy_roll, easy_norm, easy_roll, set_difficulty(), NULL, NULL);
	button ( 325, 350, medium_roll, medium_norm, medium_roll, set_difficulty(), NULL, NULL);
	button ( 325, 400, hard_roll, hard_norm, hard_roll, set_difficulty(), NULL, NULL);
	button ( 325, 450, impossible_roll, impossible_norm, impossible_roll, set_difficulty(), NULL, NULL);

function set_difficulty ( button_number, panel)
{
	start_pan.visible = OFF;
	if(button_number == 1)
	{
		computer_speed = 2;
		ball_speed = 1;
	}
	if(button_number == 2)
	{
		computer_speed = 4;
		ball_speed = 2;
	}
	if(button_number == 3)
	{
		computer_speed = 6;
		ball_speed = 3;
	}
	if(button_number == 4)
	{
		computer_speed = 10;
		ball_speed = 5;
	}
	player_pan.visible = ON;
	controls_pan.visible = OFF;
}



This saved me only about 9 lines but I was only using 4 buttons and my code is a lot more readable I think, even though i didn't add any comments smile.

edit: I was also wondering if there is some way to reset the game so to speak? Once the game ends I want you to play it again, and I am doing this by resetting all the vars to there default values and going back to the first panel but there are some issues with this that I cant seem to fix. Is there some restart_game function lol.

Last edited by halfpint; 02/21/09 23:39.

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

Gamestudio download | 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