Turn Panels of and on - depending on a variable

Posted By: TheShooter

Turn Panels of and on - depending on a variable - 10/05/12 09:05

Hi,
I'm trying to hide my ammopanel, when the variable armed = 0. And I want also to show panels for different weapontypes depending on the value of armed.
E.g.
armed = 1 - pistolammo
armed = 2 - rifleammo

I also tried to work with INVISIBLE and TRANSLUCENT, but both don't work for me. Since I noticed that INVISIBLE is only for Level-Entitys, I worked with TRANSLUCENT from this point.

Here's my code so far:

The ammo and armed variables are global.

Code:
function hud()
{
	//armed = 0 - unarmed
	//armed = 1 - Pistol
	//armed = 2 - Rifle
	//armed = 3 - Shotgun
	PANEL* pistol_muni_pan =
	{
		digits(1450,925,3,"Arial#150b",1,ammo_pistol);
		flags = TRANSLUCENT;
	}
	pistol_muni_pan.alpha = 0;
	
	PANEL* rifle_muni_pan =
	{
		digits(1450,925,3,"Arial#150b",1,ammo_rifle);
		flags = TRANSLUCENT;
	}
	rifle_muni_pan.alpha = 0;
	
	while(armed > 0)
	{
		switch(armed)
		{
			case 1:
			pistol_muni_pan.alpha = 100;
			
			case 2:
			rifle_muni_pan.alpha = 100;
			
		}
		wait(1);
	}
	pistol_muni_pan.alpha = 0;
	rifle_muni_pan.alpha = 0;
}



Am I doing something wrong? I did this a year ago the same way, and it worked just fine. (unfortunately I don't have the code any more)

Would be really thankful for help,
Shooter
Posted By: MasterQ32

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:06

you should really just take a look in the manual under Panel->Panel Properties->Flags....
RTFM
Posted By: TheShooter

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:08

I did already, and found this:

TRANSLUCENT
Das Panel wird seinem alpha-Parameter entsprechend transparent gezeichent.


Which means at english, that the panel gets transparent with it's alphavalue.

And exactly this I tried in my code, since INVISIBLE didn't seem to work.
Posted By: MasterQ32

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:22

INVISIBLE is for entities only
just try to use SHOW instead of invisible ^^ (and don't forget: SHOW is positive, IVISIBLE negative)
Posted By: TheShooter

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:34

Yes, I use SHOW to make them visible. But what can I use to make them invisible again? (!SHOW would be useful)
I can't use toggle, because the panelmanagement is in a while, which would lead to complete chaos. grin

regards,
TheShooter
Posted By: MasterQ32

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:45

what about reset(pan, SHOW); ??
Posted By: PadMalcom

Re: Turn Panels of and on - depending on a variable - 10/05/12 09:50

reset switches a flag off, set switches it on.

In particular: reset(pan, SHOW) makes your panel invisible, set(pan, SHOW) makes it visible.
Posted By: TheShooter

Re: Turn Panels of and on - depending on a variable - 10/05/12 10:05

AH, thank you, I didn't know this command.

The fully working code: (In the case someone needs such a code)

Code:
function hud()
{
	//armed = 0 - unarmed
	//armed = 1 - Pistol
	//armed = 2 - Rifle
	//armed = 3 - Shotgun
	PANEL* pistol_muni_pan =
	{
		digits(1450,925,3,"Arial#150b",1,ammo_pistol);
	}
	
	PANEL* rifle_muni_pan =
	{
		digits(1450,925,3,"Arial#150b",1,ammo_rifle);
	}
	
	PANEL* shotgun_muni_pan =
	{
		digits(1450,925,3,"Arial#150b",1,ammo_shotgun);
	}
	
	while(1)
	{
		switch(armed)
		{
			case 1:
			{
				set(pistol_muni_pan, SHOW);
				reset(rifle_muni_pan, SHOW);
				reset(shotgun_muni_pan, SHOW);
				break;
			}
			case 2:
			{
				set(rifle_muni_pan, SHOW);
				reset(pistol_muni_pan, SHOW);
				reset(shotgun_muni_pan, SHOW);
				break;
			}
			
			case 3:
			{
				set(shotgun_muni_pan, SHOW);
				reset(pistol_muni_pan, SHOW);
				reset(rifle_muni_pan, SHOW);
				break;
			}
			
			default:
			reset(pistol_muni_pan, SHOW);
			reset(rifle_muni_pan, SHOW);
			reset(shotgun_muni_pan, SHOW);
			
		}
		wait(1);
	}

}



Thank you,
Shooter
Posted By: PadMalcom

Re: Turn Panels of and on - depending on a variable - 10/05/12 10:21

Hey, eine kleine Verbesserung noch:

- Setze die Panel-Definitionen (PANEL* pistol_muni_pan...) nicht in eine Funktion. Sonst kannst du später nicht von außen darauf zugreifen falls das mal nötig werden sollte.

P.S. Sehr schön formatierter Quelltext laugh

EDIT: Und ich finde es toll, dass du die fertige Lösung nochmal postest!!!
Posted By: TheShooter

Re: Turn Panels of and on - depending on a variable - 10/05/12 10:56

Alles klar, danke für den Tip. laugh
© 2024 lite-C Forums