functions

Posted By: sadsack

functions - 09/28/08 00:38

hello,
Can some one tell me why this function is not working.
This is very simple code.
Code:

#include <acknex.h>;   //You need these includes at the start of your main script.
#include <default.c>;


//////////////////////////////declared function/////////////////////////////////////////////////////////////
function one();


function main()
{
 //This section happens once when the function is run initially
 level_load("");
 wait(3);  //Wait required for level load
} 
 
 
 ////////////////////////////////calling the function//////////////////////////////////////////////////////
 while(1)
 { 
  //This section happens every frame due to a while loop.
       
     
    
    one();

  

}                                
 
     wait(1);


/////////// function////////////////////////////////////////////////////////////////////////////////
 function one()
 {
 	
  
 	
 	{sys_exit("bye bye...");} 
 	
 	
 	
 	
}






Thank you
renny
Posted By: GamerX

Re: functions - 09/28/08 12:50

Code:

#include <acknex.h>;   //You need these includes at the start of your main script.
#include <default.c>;


//////////////////////////////declared function/////////////////////////////////////////////////////////////
function one();


function main()
{
 //This section happens once when the function is run initially
 level_load("");
 wait(3);  //Wait required for level load
one();                              	
}

/////////// function////////////////////////////////////////////////////////////////////////////////
 function one()
 {
 	
 	sys_exit("bye bye...");
 	 
 	
 	
 	
}



You don't need a while loop unless you intend on calling it more than one time and in this case you can't.
Posted By: sadsack

Re: functions - 09/28/08 14:58

Why does this function does not work in the while loop. I plan on having more than one function.
Thank You
renny
Posted By: GamerX

Re: functions - 09/28/08 15:15

You can put it in a while loop if you want just make sure the loop is in a function like in this case in the main function

Code:

#include <acknex.h>;  
#include <default.c>;


//////////////////////////////declared function/////////////////////////////////////////////////////////////
function one();


function main()
{
 //This section happens once when the function is run initially
 level_load("");
 wait(3);  //Wait required for level load
 
 while(1)
 { 
  //This section happens every frame due to a while loop.
       
     
    
    one();

      wait(1);

}                                
 
 }


/////////// function////////////////////////////////////////////////////////////////////////////////
 function one()
 {
 	
  
 	
 	sys_exit("bye bye...");
 	
 	
 	
 	
}


See? Need it in a function or its just sitting there doing nothing.
Posted By: sadsack

Re: functions - 09/28/08 16:56

Thank you GamerX I could not think why that would not work, But thanks to you I see how importance {} are now.
Thanks renny
© 2023 lite-C Forums