[ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

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.

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nash » Thu Feb 23, 2017 2:25 am

ZZYZX wrote:Otherwise if you mean that both handlers receive it, that's how it should be. You are supposed to look at e.Name and only handle events that you need to handle.


Thanks, filtering what happens through e.Name solves my problem.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nero » Thu Feb 23, 2017 10:03 pm

Nash wrote:
Code: Select allExpand view

bind Shift netevent SprintHandler


Where's this supposed to go? I can't even begin to fiddle with this if the examples are only snippets.

ZZYZX wrote:You are supposed to look at e.Name and only handle events that you need to handle.


"Name" appears to be a string, is something like this acceptable?
Code: Select allExpand view
if (e.Name == "Shift")
{
     ... blah
}


And lastly, I'm trying to read just the left mouse button for a click and just print a message to console, however I get no response .
What would be the correct way to do this?
Code: Select allExpand view
class zWinLeftClickHandler : StaticEventHandler
{
    override void ConsoleProcess(ConsoleEvent e)
    {
        Console.Printf("%s: activated by player %d [%s]", e.Name, e.Player, players[e.Player].mo.GetClassName());
    }

   override bool InputProcess (InputEvent e)
   {
      if (e.KeyScan == EDoomInputKeys.Key_Mouse1)
      {
         //ConsoleProcess(zWinLeftClickHandler.Create(ConsoleEvent));
         Console.Printf("Mouse1 was activated");
      }
   }
}

Spoiler: "Old Test Code"



Just a final thought too: I won't post code snippets if everyone else won't. We'll all benefit from being able to see an entire class or an entire file when posting questions and help.

Edit: forgot to indicate that Type_LButtonClick is the unknown identifier
Edit2: Switched to an InputEvent and did figure out that enum.val works - old test has been spoilered
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Fri Feb 24, 2017 1:05 am

Nero wrote:
Nash wrote:
Code: Select allExpand view

bind Shift netevent SprintHandler


Where's this supposed to go?

Into the console or into KEYCONF or whatever. That's only needed if you need networked special player input.

Nero wrote:
ZZYZX wrote:You are supposed to look at e.Name and only handle events that you need to handle.


"Name" appears to be a string, is something like this acceptable?
Code: Select allExpand view
if (e.Name == "Shift")
{
     ... blah
}

Yes.

Nero wrote:And lastly, I'm trying to read just the left mouse button for a click and just print a message to console, however I get no response .
What would be the correct way to do this?
[...]

Try logging all input and see what number mouse1 uses, then check enum in InputEvent. It may be a bug.
Edit: the key word here is "enum in InputEvent". Don't use the E...blablabla. That's one added by Graf for menus for whatever reason and it's apparently not compatible. (most likely it's compatible with UiEvent keys, but meh...)
I personally think menus should use UiEvent and UiEvent key enum, because it's more user-friendly than the Doom event struct, +duplicating enums is a bad idea.

Nero wrote:Just a final thought too: I won't post code snippets if everyone else won't. We'll all benefit from being able to see an entire class or an entire file when posting questions and help.

Hahaha. I don't think this is the right thread to post threats like that.

Nero wrote:Edit2: Switched to an InputEvent and did figure out that enum.val works - old test has been spoilered

So this means that the mouse problem is solved? How?
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nero » Fri Feb 24, 2017 1:36 am

ZZYZX wrote:Into the console or into KEYCONF or whatever. That's only needed if you need networked special player input.

Ah, ok. What Nash had there was a console bind, I think. That would explain why it looked odd to me, I normally setup binds in KEYCONF.


Try logging all input and see what number mouse1 uses, then check enum in InputEvent. It may be a bug.
Edit: the key word here is "enum in InputEvent". Don't use the E...blablabla. That's one added by Graf for menus for whatever reason and it's apparently not compatible.

What? I get the first part, see what what value mouse1 is assigned in the InputEvent enum, no problem. How am I supposed to determine what "e.KeyScan" is?
Or is that not even the right way to detect that mouse1 was used?

Hahaha. I don't think this is the right thread to post threats like that.

Oh, I didn't mean that as a threat, a suggestion was all.

Nero wrote:Edit2: Switched to an InputEvent and did figure out that enum.val works - old test has been spoilered

So this means that the mouse problem is solved? How?

No, my mistake, I probably forgot to save between builds. Now I get "Unknown identifier 'EDoomInputKeys'". So that's not right either.
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Fri Feb 24, 2017 1:39 am

if (e.KeyScan == EDoomInputKeys.Key_Mouse1)

You need to use InputEvent.Key_Mouse1.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nash » Fri Feb 24, 2017 1:56 am

Nero, have a look at the built-in menu classes in zscript/menu ... I am imagining if ZWindows were to be done in ZScript, it would most probably be a generic Menu class. See the following 2 files for a small taste of what you can actually do

viewtopic.php?p=978168#p978168
viewtopic.php?p=978630#p978630

My custom menu example shows you where you hook things up and where the entry points are, hopefully it is clearly commented enough

I imagine ZWindows to be a Menu object and you'd code all your custom widgets from there.

Also look at the modifications AFADoomer did to the built-in Strife conversation: viewtopic.php?p=979507#p979507

You have all of the mechanics you need built-in into the engine and ready to use for you - mouse input, text input, built-in menu events (like the up/down/left/right/enter/esc keys) that you can check, you can also check for raw input keys, clean-scale/clean pixel drawing... and doing things in ZScript allows you to use more complicated data types instead of having to fight for it in ACS. :)
Last edited by Nash on Fri Feb 24, 2017 1:59 am, edited 1 time in total.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nero » Fri Feb 24, 2017 1:58 am

Hey that works!

But, whatever is bound to mouse1, in my case fire weapon, doesn't do anything now. :? It also fragged Z-Window's mouse control; I can move the cursor but nothing responds, my first guess is GetPlayerInput isn't working right.
Maybe a UiEvent detecting finer inputs like an actual left/right click/hold won't cause this.

If that's intentional then that means a cursor toggle will have to keep that event from firing when GUI control isn't on.

So are these events unique to each player? Also, is there any way this could be used to replace Z-Window's reliance on GetPlayerInput? Or am I looking at a full rewrite?

Edit: @Nash, examples!!!! OMG that scrolling menu is cool! That might just be an autoload now.
Last edited by Nero on Fri Feb 24, 2017 2:05 am, edited 1 time in total.
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nash » Fri Feb 24, 2017 2:01 am

For UI, you will use the native mouse input stuff. Screw GetPlayerInput.

Again, just look at how GZDoom does its built-in stock menus in zscript/menu. If GZDoom can do it, your custom Menu class will also be able to.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Fri Feb 24, 2017 2:08 am

Nero wrote:Hey that works!

But, whatever is bound to mouse1, in my case fire weapon, doesn't do anything now. :? It also fragged Z-Window's mouse control; I can move the cursor but nothing responds, my first guess is GetPlayerInput isn't working right.

return false if you don't want InputProcess to block the game. If you return true, the event will be eaten.
This is actually a feature so that you can completely prevent some event (that you handle manually) from being taken as player input.
Note that this system is NOT designed to be used with ACS. What you currently have is castrated version without any way to draw anything, and using it this way (ZScript for input, ACS for drawing) is probably going to make Graf very angry so that he disables input as well.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nero » Fri Feb 24, 2017 2:47 am

@ZZYZX
Guns fire and ZScript keeps telling me mouse1 was activated! Sweet!

Well since drawing isn't a thing yet, back to ACS for the moment, but so far my approval is high. Expect a Z-Windows port when drawing is working.
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Fri Feb 24, 2017 4:47 am

You might want to port Z-Windows to the menu system instead. Not 100% sure.
But since Graf made DIFFERENT and PARALLEL systems (as opposed to making anything an EventHandler as I initially thought), you will actually need to make an abstraction layer that'd support Z-Windows in all subsystems.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nash » Fri Feb 24, 2017 6:10 pm

Code: Select allExpand view

EventHandlers 
= "MenuKeyHandler", "SprintKeyHandler", "ModularPlayerHandler"
 


Is there a problem with adding too many handlers?

As soon as I add ModularPlayerHandler, the SprintKeyHandler becomes very unreliable and will only be fire-able about 2 or 3 times before completely not working at all.

Even if the ModularPlayerHandler has no functionality (ie it's just an empty class).
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Sat Feb 25, 2017 1:19 am

OF_Fixed was not "lazy way". It was meant for things that need to stay untouched since engine startup until engine shutdown. Isn't that what OF_Fixed is for? (idk where else to comment commits)
Also, apparently it still gets collected. I first thought it may be linking issue, but it only gets linked once, and if after that it works "3 times", and only then disappears, it means it's a GC issue.

@Nash: try logging something on WorldTick. Does the logging disappear?
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby Nash » Sat Feb 25, 2017 1:33 am

WorldTick doesn't seem to have any problems.

MenuKeyHandler and SprintKeyHandler are console event handlers. ModularPlayerHandler is an empty EventHandler class (has no code).

I'll see if I can put together a minimal and reproducible WAD. What's frustrating me currently is if I isolate the SprintKeyHandler stuff to a minimal example file, it always works (meaning I can spam the Shift button many times and the event will always fire).

The problem I'm describing currently only happens in my project. So I need to identify what element of my project I need to put into my minimal example WAD that will give you the same results as the problem I'm describing right now.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?

Postby ZZYZX » Sat Feb 25, 2017 3:14 am

Wait, so InputProcess stops working, but WorldTick (from the same handler) doesn't? That's odd. Pls really make an example wad.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests