How to change between functions?

Posted By: FutureRaptor

How to change between functions? - 12/05/10 01:37

I need to change between functions for the different cameras I have set up. Every time I press key_2 I need to turn on camera two and when I press it again switch back to the camera one function. How can I get that to work. If anybody has any idea how to switch between cameras even if they dont use my method pls help. Thanks!
Posted By: rvL_eXile

Re: How to change between functions? - 12/05/10 01:40

C-Script:
Code:
function ToggleCam()
{
 cam_num += 1;
 cam_num %= 6;
}
on_f4 = ToggleCam;

action Cam_1 //Action der Cam Entity für die erste Sequenz
{
	my.passable = on;
	my.invisible = on;
	mouse_mode=2;
	while(1)
	{

		if(cam_num==0)
		{
			vec_set(camera.x,my.x);
			vec_set(camera.pan,my.pan);
		}
	wait(1);
	}
}

action Cam_2 //Action der Cam Entity für die erste Sequenz
{
	my.passable = on;
	my.invisible = on;
	 
	while(1)
	{
		if(cam_num==1)
		{
			vec_set(camera.x,my.x);
				vec_set(camera.pan,my.pan);
		}
	wait(1);
	}
}



Small example, hope this helps.

cYa Sebastian
Posted By: MrGuest

Re: How to change between functions? - 12/06/10 22:54

easiest way i can think of
Code:
void cam_global(){
}

void cam_player(){
}

void main(){

   //...
  while(1){
    
    switch(cam_to_do){
      case 1:
        cam_global();
      case 2:
        cam_player();
    }
    wait(1);
  }
}

obviously you can use if else here instead of switch if using only 2 camera mechanics
Posted By: FutureRaptor

Re: How to change between functions? - 12/07/10 03:30

Thanks for the help. When using the IF function how can I make it so when the player presses a key(whatever key) the conditions set in the IF turn on without the player having to hold the key to make the conditions continue. I hope you get my explanation..
Posted By: 3dgs_snake

Re: How to change between functions? - 12/07/10 04:48

You need to test the keys and then store the state in a variable, You only change the variable when a key was pressed. You then only test the state of the variable.

Code:
#include <acknex.h>

#define STATE_1 1
#define STATE_2 2

// Variable initialisation
var current_state = STATE_1;

void main()
{
   ...
   while(1)
   {
      if (key_...)
      {
         current_state = STATE_1 ;
      }
      else if ( key_... )
      {
         current_state = STATE_2 ;
      }
      
      ...

      switch (  current_state )
      {
         case STATE_1:
            ...
            break;
         case STATE_2:
            ...
            break;
      }
   }
   ...
}



You can separate the codes in functions, eg handle_keys() ; do_stuff () ;
© 2023 lite-C Forums