Programming Question please help with cockpit buttons

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
317
Reaction score
126
Points
43
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
hey guys, i am trying to code a Virtual Cockpit that has a button which performs an animation. this is what i have so far in "clbkVCMouseEvent"


Code:
bool Pegasus::clbkVCMouseEvent (int id, int event, VECTOR3 &p)
{
	switch (id) 
	{
	case BUTTON_BAY1_OPEN:
			if (BAY_1Status < OPEN) BAY_1Status = OPENING;
		return true;
	case BUTTON_BAY1_CLOSE:
			if (BAY_1Status = OPEN) BAY_1Status = CLOSED;
		return true;



return true;
}
}

but the button only opens it, and does not close it :shrug: i know it's something really simple i'm doing wrong, but i don't know what... any help would be REALLY appreciated. :cheers:
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
There should be (BAY_1Status == OPEN) or (BAY_1Status > CLOSED). Otherwise you don't check if it's open but set it to open (single equals sign), and then immediately switch to CLOSED (only if OPEN carries a value different than 0).

If you want to make sure there is no similar error somewhere else, flip the order when you check conditions, i.e. "if (OPEN = BAY_1Status)" would cause an error.

Additionally, shouldn't the status be set to CLOSING instead of CLOSED?

But I don't know how you defined the BAY_1Status and how the status is tested for performing animation.

There may be actually no CLOSING in the enum at all, and what I said would cause a compiler error, or there may be also wrong condition checking when the animation is performed. I can't really tell, because I can't see the code.
 

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
317
Reaction score
126
Points
43
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
ah, i've got it working now :) thanks anyway, somehow this worked:

Code:
bool Pegasus::clbkVCMouseEvent (int id, int event, VECTOR3 &p)
{

BUTTON_BAY1_OPEN;
			if (BAY_1Status == CLOSED) BAY_1Status = OPENING;

BUTTON_BAY1_CLOSE;
			if (BAY_1Status == OPEN) BAY_1Status = CLOSING;

		return true;



return false;
}

figured that with just trial-and-error, thanks anyway for your help :cheers:
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
ah, i've got it working now :) thanks anyway, somehow this worked:
...
figured that with just trial-and-error, thanks anyway for your help :cheers:

"Somehow it worked by trial and error" is not generally a unit testing strategy I would recommend. :blink:

Did you test for an opening request while the door is closing?
 
Top