[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.

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!)
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

[I will return to my previous issue later, it's not urgent and something else came up]

@ZZYZX: I made an Event suggestion: https://mantis.zdoom.org/view.php?id=466
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

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

Post by Graf Zahl »

Major Cooke wrote:I think he was trying to make a system where he could open and close the menu with the same keybind? (Correct me if I'm wrong.)

Whatever. What I find ironic is that the engine finally gets opened up, and yet the first thing Nash and you are trying to do is still working mostly against the new features and try pushing the boundaries. But as things are, right now that's really not on my agenda.
I still want to export two more subsystems (working on the statusbar/HUD right now, the last one being the map thinkers) before thinking about making it better.
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

With all due respect, I didn't even explain what I was trying to do yet and you assumed I was purposely trying to break the engine.

If you must know, actually I wasn't even sure what I was trying to do when I made the post. I THOUGHT I had to send the open menu command through the NetworkProcess but it turns out I don't need to. What I should have done is just bind a button to "netevent OpenMenu <WhateverMenu>".

So okay fine, it was a lack of technical understanding. But the motivation was definitely NOT to break the engine and try to do things the engine was not meant to do. -_-

Hence why I said "it's not urgent". It wasn't even a big deal and I learned I wasn't even doing the correct thing in the first place.
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

Okay, now I remember the other thing I wanted to try related to that menu issue.
Graf Zahl wrote:Any reason you are seinding that through the network?

In your own words, Graf:
The main problem here is that all the requested use cases require custom network protocol handling and that's unfortunately not that easy to do. Having a menu open is a one-liner function but it's an open invitation to use it wrong.
The issue was closed back then (at my request too, even) because back then before the Play/UI restrictions, it was possible to directly call Menu.SetMenu.

Now the restriction is in place, and according to you, it has to be done through network calls.

Yet with 2.4, this does not work anymore.

So my question is relevant after all: how do I call an open menu from play classes, then? The motivation is the same as the original ticket: I need a scripted way to open a menu.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

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

Post by Graf Zahl »

Actually, Menu.SetMenu should not be blocked for Play. I think ZZYZX was a bit overzealous by blocking this stuff.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

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

Post by ZZYZX »

I didn't do it
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

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

Post by Graf Zahl »

It's generally blocked by the separation, but this function needs to be 'clearscope' so that the game can open menus.
User avatar
Major Cooke
Posts: 8193
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

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

Post by Major Cooke »

Graf Zahl wrote:Whatever. What I find ironic is that the engine finally gets opened up, and yet the first thing Nash and you are trying to do is still working mostly against the new features and try pushing the boundaries.
Not intentionally, but to me, the menu screams player purchasing shops like none other. Besides, someone would've attempted it sooner or later.
And, I agree. Menu.SetMenu being allowed usage would be very ideal.
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

Alright, noted. Made a new ticket. Thanks!

https://mantis.zdoom.org/view.php?id=471
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

What is the best way to get a return value from Network events? I'm trying to do some play <-> UI stuff that requires passing information back and forth. Halp.

I need the UI class to query some world stuff and retrieve information about the world (coordinates and Actors if possible).
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

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

Post by ZZYZX »

But you can do that directly?
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Post by Nash »

ZZYZX wrote:But you can do that directly?
Indeed... I can't remember why I couldn't get it to work before.

Next question, since you wrote the events stuff, I'm sure you know the answer to this.

Code: Select all

class LADCharacterMenu : GenericMenu
{
    override bool OnInputEvent(InputEvent ev)
    {
        Console.Printf("%d", ev.KeyScan);
        return Super.OnInputEvent(ev);
    }
}
 
How is OnInputEvent supposed to even be used? It's supposed to show what key is being pressed, but it only prints ONCE when the menu is opened for the first time. Additionally, it doesn't seem like OnInputEvent is able to be fired repeatedly - it only fires once when the menu is spawned, then you can never poll any input anymore, it just does not respond.

I want this to fire repeatedly.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

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

Post by Gutawer »

OnInputEvent gets triggered for keys when they are either pressed down or released (you can use ev.type to determine which, e.g. ev.Type == InputEvent.Type_KeyDown), IIRC. If you want to track a key being currently pressed down, you can track it with a bool - set to true on key down, set to false on key up. If you want to track the entire keyboard, you may want to use something like an enum and an int, like with player.buttons (or GetPlayerInput()). You can then test for input using the & operator, just like with player.buttons.
User avatar
Sarah
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)/¯ ?

Post by Sarah »

Just want to check, are event handlers global or does each player get their own unique copy?

Return to “Scripting”