Thanks, filtering what happens through e.Name solves my problem.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.
[ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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!)
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!)
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
-
- Posts: 551
- Joined: Wed Sep 06, 2006 12:36 pm
- Preferred Pronouns: She/Her
- Operating System Version (Optional): Debian 11 (bullseye), Windows 10
- Location: Middle of Nowheresville Il.
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
Where's this supposed to go? I can't even begin to fiddle with this if the examples are only snippets.Nash wrote:Code: Select all
bind Shift netevent SprintHandler
"Name" appears to be a string, is something like this acceptable?ZZYZX wrote:You are supposed to look at e.Name and only handle events that you need to handle.
Code: Select all
if (e.Name == "Shift")
{
... blah
}
What would be the correct way to do this?
Code: Select all
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
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
Into the console or into KEYCONF or whatever. That's only needed if you need networked special player input.Nero wrote:Where's this supposed to go?Nash wrote:Code: Select all
bind Shift netevent SprintHandler
Yes.Nero wrote:"Name" appears to be a string, is something like this acceptable?ZZYZX wrote:You are supposed to look at e.Name and only handle events that you need to handle.Code: Select all
if (e.Name == "Shift") { ... blah }
Try logging all input and see what number mouse1 uses, then check enum in InputEvent. It may be a bug.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?
[...]
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.
Hahaha. I don't think this is the right thread to post threats like that.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.
So this means that the mouse problem is solved? How?Nero wrote:Edit2: Switched to an InputEvent and did figure out that enum.val works - old test has been spoilered
-
- Posts: 551
- Joined: Wed Sep 06, 2006 12:36 pm
- Preferred Pronouns: She/Her
- Operating System Version (Optional): Debian 11 (bullseye), Windows 10
- Location: Middle of Nowheresville Il.
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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.ZZYZX wrote:Into the console or into KEYCONF or whatever. That's only needed if you need networked special player input.
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?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.
Or is that not even the right way to detect that mouse1 was used?
Oh, I didn't mean that as a threat, a suggestion was all.Hahaha. I don't think this is the right thread to post threats like that.
No, my mistake, I probably forgot to save between builds. Now I get "Unknown identifier 'EDoomInputKeys'". So that's not right either.So this means that the mouse problem is solved? How?Nero wrote:Edit2: Switched to an InputEvent and did figure out that enum.val works - old test has been spoilered
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
You need to use InputEvent.Key_Mouse1.if (e.KeyScan == EDoomInputKeys.Key_Mouse1)
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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. :)
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.
-
- Posts: 551
- Joined: Wed Sep 06, 2006 12:36 pm
- Preferred Pronouns: She/Her
- Operating System Version (Optional): Debian 11 (bullseye), Windows 10
- Location: Middle of Nowheresville Il.
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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.
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 Sarah on Fri Feb 24, 2017 2:05 am, edited 1 time in total.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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.
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.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
return false if you don't want InputProcess to block the game. If you return true, the event will be eaten.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.
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.
-
- Posts: 551
- Joined: Wed Sep 06, 2006 12:36 pm
- Preferred Pronouns: She/Her
- Operating System Version (Optional): Debian 11 (bullseye), Windows 10
- Location: Middle of Nowheresville Il.
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
@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.
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.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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.
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.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
Code: Select all
EventHandlers = "MenuKeyHandler", "SprintKeyHandler", "ModularPlayerHandler"
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).
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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?
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?
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
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.
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.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: [ZScript] How Do EventHandlers ¯\(°_o)/¯ ?
Wait, so InputProcess stops working, but WorldTick (from the same handler) doesn't? That's odd. Pls really make an example wad.