Parent/child coding help

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
I have got a parent child that compiles ok. but doesn't do what I want.
I want a turret to rotate and then the gun which is part of the turret to elevate.

Code:
ANIMATIONCOMPONENT_HANDLE parent;


       static UINT EGrp20[4] = {0,15,50,58};
       static UINT EGrp21[3] = {0,15,58};
       


static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.716,-1.701), _V(0,1,0), (float)(360*RAD));
   
 GUN = new MGROUP_ROTATE(0,EGrp21, 3, _V(0,1.716,-1.701), _V(0,0,1), (float)(90*RAD));
  
  anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
   anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_TURRET, 0, 1, GUN, parent);  
  
...

 //turrent

double db = simdt * LIFT_SPEED;

    if (TURRENT_proc > 1) TURRENT_proc = (TURRENT_proc - 1);
    else if (TURRENT_proc < 0) TURRENT_proc = (TURRENT_proc + 1);

   if (TURRENT_check == 1)TURRENT_proc = (TURRENT_proc + db);
    else if (TURRENT_check == 2)TURRENT_proc = (TURRENT_proc - db);
    else if (TURRENT_check == 0)TURRENT_proc = TURRENT_proc;

    SetAnimation (anim_TURRET, TURRENT_proc);

}
{
        
  //GUN

double dc = simdt * LIFT_SPEED;

    if (GUN_proc > 1) GUN_proc = (GUN_proc - 1);
    else if (GUN_proc < 0) GUN_proc = (GUN_proc + 1);

   if (GUN_check == 1)GUN_proc = (GUN_proc + dc);
    else if (GUN_check == 2)GUN_proc = (GUN_proc - dc);
    else if (GUN_check == 0)GUN_proc = GUN_proc;

   SetAnimation (anim_gun, GUN_proc);

}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Coding issue

I have run into an issue:
I have this in my H file:
Code:
enum IGNITION_check { START_YES, NO_START } IGNITION_check;

and this in the CPP:
Code:
IGNITION_check = NO_START;

                             
    case OAPI_KEY_K: // ignition
       if(IGNITION_check == NO_START)
{
//do something unless ignition is true
PlayVesselWave3(JohnSoundID,START,NOLOOP,255,22100);
IGNITION_check = START_YES;
}
      return 1;
    case OAPI_KEY_W: // fire
 

PlayVesselWave3(JohnSoundID,CANNON,NOLOOP,255);      
        
}
return 0;
}

What should happen one presses K and if is IGNITION_check is NO_START then play a wav and set IGNITION_check to START_YES.

What happens is one presses k and the wav is played. But if you press K again the wav is played. It should only play one time.
 

tomek

legal alien
Joined
Mar 26, 2008
Messages
181
Reaction score
1
Points
0
Website
www.orbiter-forum.com
The second snippet doesn't really help much. It's apparent that something sets IGNITION_check back to NO_START, but from code given, there's really no way to tell where and how it might happen.

As a wild guess, are all of your cases terminated by return or break? Cause it doesn't stop when it hits the next case label, only when it hits break, return, or the end of block.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
maybe. I first had it set as 0 ignition off and 1 start. I could see that ignition valve was 0 until K was pressed then it became 1. And remained even though K was pressed.
Here is the rest of the code all references to IGNITION_check:
Code:
MOBILE3C::MOBILE3C (OBJHANDLE hVessel, int flightmodel)
        : VESSEL2 (hVessel, flightmodel)
{

RDOOR_status = RDOOR_UP;
IGNITION_check = NO_START;
RDOOR_proc = 0;
LIFT_SPEED =.25;
t1 = 1;
i2l = 0.5;
i2r = 0.5;
i2=.5;
TURRET_check = TM_STOP;
TURRET_proc=0;
GUN_proc=0;

GUN_check=0;    
    DefineAnimations ();
    
}
....


if (IGNITION_check == YES_START){     
    {PlayVesselWave3(JohnSoundID,ENG,LOOP,sp,pit);
...

if (IGNITION_check == NO_START){
    
        SetThrusterGroupLevel(th_main,0);
....
  if (IGNITION_check == YES_START){
        
        
        SetThrusterMax0 (th_main ,9000);
....





   case OAPI_KEY_K: // ignition
       if(IGNITION_check == NO_START);
      
{
//do something unless ignition is true
PlayVesselWave3(JohnSoundID,START,NOLOOP,255,22100);
IGNITION_check=YES_START;
}
      return 1;
    case OAPI_KEY_W: // fire
 

PlayVesselWave3(JohnSoundID,CANNON,NOLOOP,255);      
        
}
return 0;
}
I went with the yes_start and No_start so it would be easier to read the code.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Fixed. I think it was the extra semi colon on this line:
Code:
case OAPI_KEY_K: // ignition
          if(IGNITION_check == NO_START)[COLOR=Red];[/COLOR]// n
 
Top