Blocking without pausing (or, creating a non-pausing but blocking Display())

Started by frission, Wed 10/10/2007 02:32:18

Previous topic - Next topic

frission

Though the manual says Display() is blocking, it seems that it actually is Pausing (it stops even repeatly_execute_always, for example, and will jump ahead in the event cue so that some actions immediately in front of it won't execute without a Wait(1) in place).

Since a non-pausing, just-blocking Display() seems like a rather big feature request (and since the last request for it I found on the forums was from 3 years ago, it doesn't seem very popular), I was trying to create my own little Display() GUI that wouldn't interfere with my repeatedly_execute_always() commands.

So far what I realize I'd like is a command that would wait for the user to hit a key (space, return, whatever) and then release program flow. But it would be blocking, not pausing â€" so things in repeatedly_execute_always() would still work.

I've searched through the manual but I didn't find anything, unfortunately. The Wait() commands seem to require time-out settings (though I could loop it, I guess), but they are pausing anyway, yes?

Any idea as to get this sort of functionality? It feels like it should be do-able, even if it is done in a semi-hacky way. Am I totally crazy? Have I gone off the deep end? :-)

Thanks a bunch guys, you've been really helpful...

SSH

12

Khris

It should be possible by

-displaying the message
-pausing the game
-putting stuff in rep_ex_always that'll un-pause the game.

frission

Quote from: KhrisMUC on Wed 10/10/2007 08:09:33
It should be possible by

-displaying the message
-pausing the game
-putting stuff in rep_ex_always that'll un-pause the game.

This doesn't work. Running Display() pauses the game; if I put an
Code: ags
if (IsGamePaused() == 1) UnPauseGame();
into repeately_execute_always, the message is simply never displayed (or vanishes before the screen even updates). :-/

frission

Quote from: SSH on Wed 10/10/2007 07:28:52
I think I put such a thing in my Hypertext module
OK, I'll check that out and see if it works with what I'm trying to do.

(Note that the other reason I hate Display() as it is is that it greedily seems to push itself to the front of any procedure flow. So if I tell a guy to walk to a spot, turn around, and then Display() a message about the location, he will walk, and then Display(), and then after they hit Enter he turns around. Arrggg. Of course I can add Wait(1) before each Display() but what a pain.)

frission

OK! I was wrong on one point -- Wait() is NOT Pausing, it is JUST Blocking, despite the wording in the manual.

So what this means is that if I make my custom display function call WaitKey(big number here), it basically works like a non-pausing, just-blocking Display() except that it will expire after a certain amount of time. Which is fine.

Khris

What I meant by "putting stuff in rep_ex_always that'll un-pause the game" was "put code in there that will un-pause the game after a key press or mouse click".

If it's a pain to add "Wait(1)" everytime, use a custom function.

Code: ags
function Disp(String s) {
  Wait(1);
  Display(s);
}

That should work.

frission

Quote from: KhrisMUC on Thu 11/10/2007 00:31:26
What I meant by "putting stuff in rep_ex_always that'll un-pause the game" was "put code in there that will un-pause the game after a key press or mouse click".

I'm a little confused about what you mean here?

frission

Here is my final blocking-but-not-pausing Display replacement. Basically all it requires other than the code below is to create a GUI named gDisplay with a Label control on it named dLabel, and set the view mode to Normal (but make sure a gDisplay.Visible = false; is added in your game_start).

Any suggestions for improvements are welcome, but I'm pretty happy with this at the moment, and I'm super happy that I can change the font and margins with this replacement (the default font for Display() is very ugly, and the margins are way too close to the text IMO). Basically this is pretty much the same as Display() except rep_ex_always is allowed to continue, which in my case allows for some other animation (namely the typewriter effect I mentioned in another thread) to continue without pausing awkwardly. I imagine it could also be useful for things like repeated animations (e.g. fire) that you wanted to persist.

Note that in my case I have a pure text parser GUI (no mouse at all) that I am hiding here when the display window is open; if you were using a mouse control system I imagine you would do something else to indicate that input was "paused".

Code: ags
function dDisplay(String message) {
	gDisplay.Width = 250; //reset to max width
	dLabel.Width = 244; //reset to max width
	if(GetTextWidth(message, dLabel.Font) < dLabel.Width) { //shrink width if just a little bit of text
		int rMargin = (gDisplay.Width - dLabel.Width)/2; //make sure it has the same right hand margin as before
		dLabel.Width = GetTextWidth(message, dLabel.Font)+4; //new label width -- pad it a little because sometimes GetTextWidth comes up a few pixels short
		gDisplay.Width = dLabel.Width + rMargin; //set right margin of GUI
	}
	dLabel.Height = GetTextHeight(message,dLabel.Font,dLabel.Width); //resize height
	gDisplay.Height = dLabel.Height + (dLabel.Y*3);
	dLabel.Text = message; //set message
	gDisplay.Centre(); //center 
	gDisplay.Visible = true; //make this GUI visible
	gTextparser.Visible = false; //make parser invisible
	WaitKey(2400); //display for a minute, or wait until they hit a key
	gTextparser.Visible = true; //make parser GUI visible
	gDisplay.Visible = false;	 //make this GUI invisible
}

SMF spam blocked by CleanTalk