Hi, I'm having a slight problem that I managed to solve in a very culmsy way but I'd like to ask about the issue I was having anyway.
The problem I had was that I have a journal screen and when I open it I want the game to pause but the problem was that the game didn't pause when I used this script:
bool open = false;
function change_journal(String text, int bgraph)
{
if (IsGamePaused() == 0) PauseGame();
J_Text.Text = text;
gJournal.BackgroundGraphic = bgraph;
if (open == false)
{
gdarken.Visible = true;
gJournal.Visible = true;
while (gJournal.Transparency >= 20)
{
gJournal.Transparency -= 20;
Wait(1);
}
gJournal.Transparency = 0;
open = true;
}
aFlip_paper_once.Play();
}
void j_buttons(Button *b)
{
if (b == J_notes){
change_journal("Notes", 269);
if (IsGamePaused() == 0) PauseGame();
j_clicked = true;
}
else if (b == J_diary){
change_journal("Diaries", 266);
if (IsGamePaused() == 0) PauseGame();
j_clicked = true;
}
else if (b == J_misc){
change_journal("Misc", 268);
if (IsGamePaused() == 0) PauseGame();
j_clicked = true;
}
else if (b == J_memo){
change_journal("Memo", 267);
if (IsGamePaused() == 0) PauseGame();
j_clicked = true;
}
else if (b == J_close)
{
j_clicked = false;
gdarken.Visible = false;
while (gJournal.Transparency <= 80)
{
gJournal.Transparency += 20;
Wait(1);
}
gJournal.Transparency = 100;
gJournal.Visible = false;
open = false;
aNotesclose.Play();
if (IsGamePaused() == 1) UnPauseGame();
}
}
Which is weird, even more strange is that the game seemed to pause and unpause within half a second after opening the journal. Which shouldn't happen since b never was changed to J_close (which happens when clicking the close button). If I change if (IsGamePaused() == 0) PauseGame(); to just PauseGame(); and if (IsGamePaused() == 1) UnPauseGame(); to just UnPauseGame(); it sort of works but the problem now is that if I give b a new value numerous time (that is, flipping between misc and memo for example) then the PauseGame() seem to stack? When I close the journal, the game doesn't unpause unless I squeeze additional UnPauseGame(); into the script like this:
bool open = false;
function change_journal(String text, int bgraph)
{
PauseGame();
J_Text.Text = text;
gJournal.BackgroundGraphic = bgraph;
if (open == false)
{
gdarken.Visible = true;
gJournal.Visible = true;
while (gJournal.Transparency >= 20)
{
gJournal.Transparency -= 20;
Wait(1);
}
gJournal.Transparency = 0;
open = true;
}
aFlip_paper_once.Play();
}
void j_buttons(Button *b)
{
if (b == J_notes){
change_journal("Notes", 269);
PauseGame();
j_clicked = true;
}
else if (b == J_diary){
change_journal("Diaries", 266);
PauseGame();
j_clicked = true;
}
else if (b == J_misc){
change_journal("Misc", 268);
PauseGame();
j_clicked = true;
}
else if (b == J_memo){
change_journal("Memo", 267);
PauseGame();
j_clicked = true;
}
else if (b == J_close)
{
j_clicked = false;
gdarken.Visible = false;
while (gJournal.Transparency <= 80)
{
gJournal.Transparency += 20;
Wait(1);
}
gJournal.Transparency = 100;
gJournal.Visible = false;
open = false;
aNotesclose.Play();
UnPauseGame();
UnPauseGame();
UnPauseGame();
UnPauseGame();
}
}
It works but I really, really don't like the solution. Can someone please clear things up for me about how PauseGame() actually works?
Thanks :)
I guess they stack, just like DisableInterface().
Try setting the GUI's visibility to popup modal; this will pause the game while the GUI is visible.
They do stack.
void PauseGame() {
game_paused++;
DEBUG_CONSOLE("Game paused");
}
void UnPauseGame() {
if (game_paused > 0)
game_paused--;
DEBUG_CONSOLE("Game UnPaused, pause level now %d", game_paused);
}
int IsGamePaused() {
if (game_paused>0) return 1;
return 0;
}
Not sure why your IsGamePaused() variant wasn't pausing the game though. Perhaps something else is interfering with it. My immediate thought was that PauseGame() might be delayed until a function exits, but as you can see above, that's not the case.
Thanks for the help guys. :)
I found the solution, I'm using function in my global script that hande GUI clicks (a method that Khris taught me a while back), what I needed to do was to add PauseGame() inside the if-statement that handle the Journal GUI clicks. Like this:
void HandleGUIClicks(GUIControl *gc, MouseButton button) {
if (button != eMouseLeft) return;
if (gc.AsButton != null) Buttons(gc.AsButton);
if (gc.AsButton != null)
{
j_buttons(gc.AsButton);
PauseGame();
}
if (gc.AsButton != null) m_buttons(gc.AsButton);
}
Now it works, without stacking should I switch to different journal types or the pause-unpause issue I had.