Operations while Paused

Started by knucracker, January 31, 2014, 11:31:37 AM

Previous topic - Next topic

knucracker

Well...  Hmmm.
After seeing things like buttons that only operate while the game is unpaused and such, maybe I should expose paused operations.

So I have added these two commands to CRPL
OperateWhilePaused(bool)
bool IsPaused

So you could do this irritating thing and get a rating of 1 on your map if you do :)

if (IsPaused) UnPauseGame endif

:Awake
OperateWhilePaused(true)


The OperateWhilePaused function toggles a state on the core that makes it continue execution even while the game is paused.  In other words, the script will keep on executing as if the game isn't paused.  So this could be used for something irritating like immediately unpausing the game.  But it could in theory also be used for good.  You could implement a button that pops up a menu and closes the menu and it will work while the game is paused.  That sort of thing.

Now, there are probably many edge cases and things that might not work properly.  So if I decide to leave this in for tonight's build I will ask for a brief period of testing before anyone publishes a map that uses it.  If things explode and it turns into a nightmare of issues, I will remove the commands.

Grayzzur

That's gonna be a can of worms. You may wind up having to disallow a bunch of CRPL commands while paused.. anything that modifies the state of the game (unit locations, terrain elevation, creeper amounts, etc.).

Instead of an IsPaused conditional, I wonder if it would be safer to have a paused function (:Paused), and only run that function while paused instead of the entire script. Such an approach may make it easier to disallow commands that shouldn't be used during pause, you could possibly weed them out when compiling the script. I know, more work, I guess we could enforce that ourselves, but I worry about the abuse.

However, it makes it possible to make custom player units much friendlier. Target while paused, etc. I can see a bunch of good stuff that could come from it. It could solve several UI issues with the CW1 style Drones I'm playing with.

Without such restrictions, you could do some evil stuff. Emitters that get stronger every time the player pauses. Reduces the ammo of player units every time the player clicks on them while paused.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

knucracker

I tried that for starters, a ":Paused" function basically.
But things like timers, the delay call, queued unit movements....  yeah.  It would be difficult to prevent them from progressing (or in the case of Delay, working).

But you are right... you can do some evil things.  That said you can already sort of do many of these evil things, you just have to be sneaky about it.  For instance, you can compare GetGameTimeFrames with ElapsedTime in CRPL... and from that you can tell when the game was paused.  ElapsedTime always goes up but GetGameTimeFrames only goes up while the game is not paused. I actually use this sort of thing in my Alpha:Virgilw:Brain map.  I want the actual clock time it takes to solve the puzzle, pauses and all.

Before this new feature you couldn't do things while the game was paused, but you could do them all immediately after the game was unpaused.

Clean0nion

If we're now able to control pausing, I think we should be able to control - or at least detect - time speed.
So for example, a map might give you bonus points if you paused infrequently and ran the game at x4 all the way through, whereas someone who runs the game slowly and pauses often would receive fewer points.

eduran

Awesome change, that makes working with UI elements a lot easier.

About the abuse cases: If someone wants to make a annoying map that is already more than possible (flooding areas with creeper when a savegame is loaded.... :-[). I don't think that disabling commands is necessary, unless they are buggy when used during pause.

pawel345

I agree :D Can't wait till somebody does a player unit GUI functions, that would make CPRL allies much more probable. :D

Clean0nion

Quote from: pawel345 on January 31, 2014, 01:03:23 PM
I agree :D Can't wait till somebody does a player unit GUI functions, that would make CPRL allies much more probable. :D
Or even just those mouseover things that show an enemy cannon's range.

Grayzzur

@V: You realize most of what I'll be doing with the pause processing will be negated the moment you decide to actually release a CRPL Core type designed to be a custom player unit. :)
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Clean0nion

I just realised how essential this whole thing is to my current project(s).

Grayzzur

Virgil, Something's not right. I downloaded/installed 1.71, pasted the :Awake function to the end of a script as you have it, and I get:

--ERRORS FOLLOW--
CW1_Drone.crpl: Line: 391: Invalid Token: OperateWhilePaused. Perhaps you meant ->OperateWhilePaused or <-OperateWhilePaused or "OperateWhilePaused" or @OperateWhilePaused
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

asmussen

Quote from: Grayzzur on January 31, 2014, 05:16:03 PM
Virgil, Something's not right. I downloaded/installed 1.71, pasted the :Awake function to the end of a script as you have it, and I get:

--ERRORS FOLLOW--
CW1_Drone.crpl: Line: 391: Invalid Token: OperateWhilePaused. Perhaps you meant ->OperateWhilePaused or <-OperateWhilePaused or "OperateWhilePaused" or @OperateWhilePaused

1.71 was released yesterday, and Virgil's post about the new functions is from today, so my guess would be that he meant that he added them to the source code, but hasn't released a beta build enabling those features yet. Maybe 1.72.
Shawn Asmussen

knucracker

Yeah this new stuff will be in tonight's build. That should be ready in a few hours.

Clean0nion

Quote from: virgilw on January 31, 2014, 05:47:13 PM
Yeah this new stuff will be in tonight's build. That should be ready in a few hours.
Excellent! Thank you so much Virgil.

Grayzzur

My bad. I read that wrong. 1.71 does have new functions... just not these new functions. I shall clean my glasses. And wait. And twiddle my thumbs.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Clean0nion

This probably isn't intentional therefore a new feature request:
Can you change OperatesWhilePaused to be something more along the lines of it operates during pauses, except when in editmode?
It doesn't effect me but might do to others. All it does to me is make a core a tiny bit harder to select.