2 registered members (TipmyPip, 1 invisible),
18,731
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
button function parameters?
#252893
02/21/09 06:17
02/21/09 06:17
|
Joined: Jun 2008
Posts: 19
halfpint
OP
Newbie
|
OP
Newbie
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. 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
Expert
|
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):
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: halfpint]
#252986
02/21/09 22:52
02/21/09 22:52
|
Joined: Jun 2008
Posts: 19
halfpint
OP
Newbie
|
OP
Newbie
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.
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  . 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.
|
|
|
|