using a back/pause options

Posted By: MarcsVision

using a back/pause options - 11/02/09 16:29

i would like to have a key that pauses the game and brings up a panel. my problem is not bringing up the panel when i hit the key, i dont know how to make the panel go away when i hit the key again.

can someone explain how to make panels or functions turn on and off with the stroke of a key.

Thanks Alot!
Posted By: DJBMASTER

Re: using a back/pause options - 11/02/09 16:44

You can use a variable that holds the state of the game...
Code:
var game_paused = 0;



So when you press 'pause' you can check this variable and act accordingly...
Code:
function PausePressed()
{
if(game_paused == 0) // game not paused
{
// show pause menu
set(pnl_pause_menu,SHOW);
game_paused = 1;
}
else // game already paused
{
// hide pause menu 
reset(pnl_pause_menu,SHOW);
game_paused = 0;
}
}


Posted By: MarcsVision

Re: using a back/pause options - 11/02/09 16:53

Thanks alot, i will see if it works for me and let you know how it turns out.
Posted By: MarcsVision

Re: using a back/pause options - 11/02/09 18:25

i might be a little confused. how do i call this pressed function?

where do i place "if (Key_P)" to make the function be called once the P key is hit and off again when pressed a second time?

thanks again
Posted By: MarcsVision

Re: using a back/pause options - 11/02/09 22:42

I wrote the scirpt as told and it runs with no syntak errors. but the game doesnt pause nor does my menu panel show when i hit the space bar. this is what i have in my scirpt:

var game_paused = 0;

function press_paused ()
{
if (key_space) {game_paused = 0;}
if (game_paused == 0)//game not paused
{
set(menu_pan, SHOW);//show menu panel
game_paused = 1;
}
else //game paused
{
reset(menu_pan, SHOW);//hide menu panel
game_paused = 0;
}
wait (1);
}

What am I doing Wrong?

Thanks
Posted By: DJBMASTER

Re: using a back/pause options - 11/03/09 05:41

hi, you have put the key call to 'press_paused' inside 'press_paused' so it can't start, lol. Functions can't start themselves, they have to be called from another function.

You can use the main function to do this. You also don't need the wait(1);.
Code:
var game_paused = 0;

function press_paused ()
{
if (game_paused == 0)//game not paused
{
set(menu_pan, SHOW);//show menu panel
game_paused = 1;
}
else //game paused
{
reset(menu_pan, SHOW);//hide menu panel
game_paused = 0;
}
}

void main() // first function that is run when game loads
{
on_space = press_paused; // set space key to use press_paused.
}


Posted By: MarcsVision

Re: using a back/pause options - 11/03/09 17:34

thanks alot for all your help DJBMASTER, im very new to Lite-C. In fact this is the first programming I ever did. the code work perfectly. and im sure i will have alot more questions as I continue to learn, lol.

Thanks Again.

-Marc
Posted By: DJBMASTER

Re: using a back/pause options - 11/04/09 06:11

no problem. Did you complete the Lite-c Workshops? If so, then you could try going through the AUMs. That will get you really familiar with the engine.
Posted By: Helghast

Re: using a back/pause options - 11/04/09 08:51

Code:
function press_paused ()
{
toggle(menu_pan, SHOW);//hide menu panel
}

void main() // first function that is run when game loads
{
on_space = press_paused; // set space key to use press_paused.
}



this is a hell of a lot easier! look up Macro's in the manual laugh

regards,
Posted By: rojart

Re: using a back/pause options - 11/04/09 09:48

or

Code:
function on_space_event()
{
	while (key_space){wait (1);}
	
	toggle(menu_pan, SHOW);
}


Posted By: MarcsVision

Re: using a back/pause options - 11/12/09 15:57

Thanks to all!
© 2023 lite-C Forums