Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Addons > Addon Support & Bugs
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Addon Support & Bugs Support & bug reports for Orbiter addons.

Reply
 
Thread Tools
Old 09-03-2017, 02:49 AM   #1
slaver0110
Orbinaut
 
slaver0110's Avatar
Default Strange thruster behavior

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...
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 is offline   Reply With Quote
Old 09-03-2017, 04:32 AM   #2
martins
Orbiter Founder
Default

Missing "break" at the end of the case statements?
martins is offline   Reply With Quote
Old 09-03-2017, 05:21 AM   #3
slaver0110
Orbinaut
 
slaver0110's Avatar
Default

Quote:
Originally Posted by martins View Post
 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!!
slaver0110 is offline   Reply With Quote
Old 09-03-2017, 12:34 PM   #4
martins
Orbiter Founder
Default

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.
martins is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Addon Support & Bugs


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 03:04 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.