Hi i've been trying to make a function that can accept parameters so i don't have to define seperate functions. I am having a couple of problems.
Scenerio 1I have this...
function beep_engine()
{
beep();
}
function main()
{
on_space=beep_engine;
}
Now if i press space, the engine will beep as expected. It beeps everytime i press space. No problems here.
Scenerio 2Now i make a function that can determine the number of beeps...
function beep_engine(num_beeps)
{
if(num_beeps==1){beep();}
if(num_beeps==2){beep();beep();}
if(num_beeps==3){beep();beep();beep();}
}
function main()
{
on_space=beep_engine(3);
}
When i run it, the engine beeps 3 times as soon as it has loaded and if i press space the engine crashes.
Am i missing something fundamental about functions? I have read through the manual on function parameters but it doesn't give any examples when pressing a key.
I also don't understand how on_space=beep_engine; is not run when the engine is opened, yet on_space=beep_engine(3); is automatically ran.
A final question to my stupidity>How come i can press the space key several times when using
on_space=beep_engine; and the engine will still beep. I thought it would have to be inside a loop of some sort for the key to be continuously checked.
I know these must be stupid questions, lol.
Thanks in advanced.