UiProcess and InputProcess events

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

UiProcess and InputProcess events

Post by Apeirogon »

This two event on wiki page warn me that if I return true with one of this event, player will be locked from moving, event with lower order stop processing, all be bad.

But there are a way to bypass this using network event. And in this point I lost thread of thought. I must override two events one of which send all input and ui events in network? Write input event inside network event? Write network event inside input?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

UiProcess and InputProcess are events to get direct access to keyboard events. Normally you don't have to return true in the events; also with InputProcess the game and the player just keeps moving. UIProcess is more meant for a kind of modal screens, at least that is where I use it for. In UIProcess you can also catch system keys like ESC and PrtScr and such, and provides also direct access to mouseX/Y coordinates and left/right/wheel button clicks.

Both events are UI bound, so you can't modify game data there; that's why the NetworkProcess event exists; when you use SendNetworkEvent in InputProcess or UiProcess, you can receive and process the information in NetworkProcess.

Very simple example for Input:

Code: Select all

	override bool InputProcess (InputEvent e)
	{
		if (e.Type == InputEvent.Type_KeyDown && automapactive == false) // not when automap is active
			SendNetworkEvent("keypress", e.KeyScan);
			
		return false;
	}


	override void NetworkProcess(ConsoleEvent e)
	{	
		if (e.Name == "keypress")	
		       console.printf("%d", e.Args[0]);
	}
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: UiProcess and InputProcess events

Post by Apeirogon »

Ooooo, send RESULT of event.
I think about sending ENTIRE event...

Also, how check buttons in input process? I mean, what name I must use for key, say "L"?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

Apeirogon wrote: Also, how check buttons in input process? I mean, what name I must use for key, say "L"?
See the console.printf in my example for the exact value; otherwise see in gzdoom.pk3 the events.txt , struct InputEvent.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

Btw, in my example I used e.KeyScan which is an internal code for the engine, but you can also use the ascii code, which is represented by e.KeyChar.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: UiProcess and InputProcess events

Post by Apeirogon »

Okay, now I know what button player press, release and how long it was pressed.

How check is this button do something inside game? Like, I want check how much time player press "use" button.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

Apeirogon wrote: Like, I want check how much time player press "use" button.
Using the same keypress command as in the previous example, it would be something like this:

Code: Select all

int used;  //<== local variable in your eventhandler class

override void OnRegister()
{
    used=0;
}

override bool InputProcess (InputEvent e)
{
      if (e.Type == InputEvent.Type_KeyDown && automapactive == false) // not when automap is active
         SendNetworkEvent("keypress", e.KeyScan);
         
      return false;
}

override void NetworkProcess(ConsoleEvent e)
{         
      
      if (e.Name == "keypress")
      {
         int key1, key2;
         [key1, key2] = Bindings.GetKeysForCommand("+use");
         if ((key1 && key1 == e.Args[0]) || (key2 && key2 == e.Args[0]))
         {
            used++;
         }
      }
}
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: UiProcess and InputProcess events

Post by Apeirogon »

Why you check two time value of argument from input event? This important?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

Apeirogon wrote:Why you check two time value of argument from input event? This important?
You mean this: if ((key1 && key1 == e.Args[0]).. ?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: UiProcess and InputProcess events

Post by Apeirogon »

More specific, why

Code: Select all

         [key1, key2] = Bindings.GetKeysForCommand("+use");
         if ((key1 && key1 == e.Args[0]) || (key2 && key2 == e.Args[0]))
instead

Code: Select all

         key = Bindings.GetKeysForCommand("+use");
         if (key && key == e.Args[0])
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: UiProcess and InputProcess events

Post by gwHero »

Because Bindings.GetKeysForCommand returns 2 values; you can have 2 keys assigned to an action.
Post Reply

Return to “Scripting”