Support Strange thruster behavior

slaver0110

Member
Joined
Mar 21, 2011
Messages
72
Reaction score
2
Points
6
I'm coding a vessel which has a separate set of special RCS thrusters in the aft of the ship, which are triggered individually fromthe RCS thrusters in the front.
The aft-thrusters are only activated when the 'L' key is pressed, which toggles the enable/disable of the rear thrusters.
Problem is, when I set up a 'clbkConsumeBufferedKey' definition for more than one of the rear thrusters, both of the aft thrusters end up firing ('up' and 'down'). If I only define one, it works as it should.

Thruster definitions:
Code:
th_pod_up = CreateThruster(_V(0.0, 0.0, -7.5), _V(0, -1, 0), T1_PODRCSTH, hpr, T1_ISP); AddExhaust(th_pod_up, 4.0, 0.2, exhaust);
th_pod_down = CreateThruster(_V(0.0, 0.0, -7.5), _V(0, 1, 0), T1_PODRCSTH, hpr, T1_ISP); AddExhaust(th_pod_down, 4.0, 0.2, exhaust);
th_pod_left = CreateThruster(_V(0.0, 0.0, -7.5), _V(1,0,0), T1_PODRCSTH, hpr, T1_ISP); AddExhaust(th_pod_left, 4.0, 0.2, exhaust);
th_pod_right = CreateThruster(_V(0.0, 0.0, -7.5), _V(-1,0,0), T1_PODRCSTH, hpr, T1_ISP); AddExhaust(th_pod_right, 4.0, 0.2, exhaust);

Keyboard implementation:
Code:
int Tug1::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate) 
{
	if (!down)							// only process keydown events
	{
		SetThrusterLevel(th_pod_down, 0);
		SetThrusterLevel(th_pod_up, 0);
		SetThrusterLevel(th_pod_left, 0);
		SetThrusterLevel(th_pod_right, 0);
		return 0;
	}	
	if (KEYMOD_SHIFT(kstate)) {}
	else 
	{
		switch (key)
		{
		case OAPI_KEY_L:				// toggle Pod activation status (on / off)
			if (PodFlag == 0)		{PodFlag = 1;}
			else if (PodFlag == 1)	{PodFlag = 0;}
			return 1;
		case OAPI_KEY_NUMPAD8:
			if (PodFlag == 1)		{SetThrusterLevel(th_pod_down, 1);}
		case OAPI_KEY_NUMPAD2:
			if (PodFlag == 1)		{ SetThrusterLevel(th_pod_up, 1);}
		}
	}
	return 0;
}
This seems to be one of those times that the problem is right in front of me, but I just can't see it...:embarrassed:
I've just started coding DLL's less than a week ago, so please bear with me if I'm throwing dumb questions at the forum for the next little while.
Cheers, and happy Labour Day Weekend!!
 

slaver0110

Member
Joined
Mar 21, 2011
Messages
72
Reaction score
2
Points
6
Missing "break" at the end of the case statements?

**bangs head off desk**

That solved it. As I said, It's probably looking me right in the face; and it was.

Just as an afterthought, though, I have been piecing together how to vessel-code from the SDK samples, and the code I used as a model was:
Code:
bool XPointerMFD::ConsumeKeyBuffered(DWORD key)
{
	switch (key) 
	{
	case OAPI_KEY_M:
		return SetMode(mode != 0 ? 0 : 1);

	case OAPI_KEY_N:
		return SetReciever(reciever + 1);

	case OAPI_KEY_COMMA:
		return SetDisplayScale(max(scale / 10.0, 1.0));

	case OAPI_KEY_PERIOD:
		return SetDisplayScale(min (scale * 10.0, 100.0));

	default:
		return false;
	}
}
I think this is where I omitted the breaks, as I didn't see them in the example code. As well, I used 'clbkConsumeBufferedKey' where the sample material used 'ConsumeKeyBuffered'...
Is there a difference?
Thank you for Orbiter, Dr.Schweiger, and Cheers!!
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
No, the "return" statements make the breaks obsolete. Any code after return is never reached. So you can put breaks there, but they would never get executed.
 
Top