[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 » Sat Feb 25, 2017 8:56 am

UGH. I cannot make a minimal WAD example because the bug doesn't happen.

I'm sending you a link to my entire project. Bind something to "netevent SprintKeyHandler". You'll get the bug very quickly with my package.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

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

Postby Nash » Sat Feb 25, 2017 8:59 am

And minimal WAD example if you still insist. Bug will not happen with this one (the SprintKeyHandler can be fired as many times as you want, it just works)
You do not have the required permissions to view the files attached to this post.
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 10:05 am

Doesn't reproduce with your full PK3 using the SprintKeyHandler. The message displays reliably 1 minute into the game, no matter how often I press the bound key.
I'm using gzdoom-x64-g2.4pre-620-g10c6b7a.
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 10:18 am

I'm using the same executable as you. Here's what I found out:

If I QUICKLY start a new game as soon as the program launches, and IMMEDIATELY hit the Sprint key; the sprinting will work and I can trigger it repeatedly.

If I take my time at the title screen, then press new game, then wait a few more seconds and try to Sprint... the sprint key won't work.

I was able to reproduce this repeatedly.
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 11:00 am

SprintKeyHandler is static, and if you put it in MAPINFO, it's supposed to be loaded at the start of the engine and persist.
Yet, for whatever reason it gets removed at exactly tic 40 in titlemap. Tested with WorldTick callback that outputs level.time.
No idea what causes this really, will build latest GZDoom later and test, if Graf can't help sooner.
I really think this might be related to the recent GC edit which made static handlers non-fixed, but as well might not be that. Looks too deterministic to be a problem with GC (it's always 40 tics...).

Can you send that archive to Graf as well pls :)
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 ZZYZX » Sun Mar 05, 2017 9:27 pm

Made an example on proper routing of input events through the network for interaction with playsim, thought I'd share here as well: http://pastebin.com/2gvzhcUu
NetworkProcess is ok to alter the world state from.
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 Major Cooke » Sun Mar 05, 2017 10:01 pm

If you want a more specific version...

Code: Select allExpand view
class TwilightPlayerHandler : EventHandler
{
    override bool InputProcess(InputEvent ev)
    {
        if (ev.Type == InputEvent.Type_KeyDown && ev.KeyChar >= 0x30 && ev.KeyChar <= 0x39) // 0x30, 0x39 are '0' and '9'
        {
            // Make sure the player exists.
            let plr = players[consoleplayer].mo;
            
            
// Why run away? It's JUST a giant nuclear purple warhorse.
            if (!plr || !plr.CountInv("PowerTwilightSparkleMorph"))
                return false;
            
            
// ev.KeyChar smells like magic.
            EventHandler.SendNetworkEvent("Pwnie_NumericKeyPressed", ev.KeyChar-0x30, 0, 0);
        }
        return false;
    }

    override void NetworkProcess(ConsoleEvent ev)
    {
        if (ev.Name == "Pwnie_NumericKeyPressed")
        {
            let plr = players[ev.Player].mo;
            
            
// player ev.Player pressed key ev.Args[0]
            // where ev.Args[0] is the key 0 through 9, apparently.
            if (plr && plr.CountInv("PowerTwilightSparkleMorph"))
            {
                plr.A_SetInventory("WeaponModeToken",ev.Args[0]);
            }
        }
    }
}


Thus I am able to have different attack modes with a morph on. Thank you so much, ZZYZX. :mrgreen:

Even if it, quite literally, runs on rocket science so powerful that it's magical. SOMEHOW.

'cuz I don't get how ev.KeyChar - 0x30 works and shit, nor what each of the three args contain.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

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

Postby AFADoomer » Sun Mar 05, 2017 10:25 pm

Major Cooke wrote:If you want a more specific version...

[snip]

Thus I am able to have different attack modes with a morph on. Thank you so much, ZZYZX. :mrgreen:

Even if it, quite literally, runs on rocket science so powerful that it's magical. SOMEHOW.

'cuz I don't get how ev.KeyChar - 0x30 works and shit, nor what each of the three args contain.


ev.KeyChar is literally just returning the ASCII code for the pressed key...

0x30 in ASCII encoding is '0'. You know that your inputs are between 0x30 and 0x39 (0-9) becasue of the first "if" statement there, so a quick way to convert your ASCII code to the equivalent integer value is to subtract 0x30 from the ASCII value.

So if the player pushes the '7' key, the game is sent ASCII code 0x37, then you subtract 0x30 from 0x37 and get 7.
User avatar
AFADoomer
 
Joined: 15 Jul 2003

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

Postby Nash » Wed Mar 08, 2017 8:38 pm

Posting because this was apparently never documented or even mentioned anywhere:

MAPINFO "AddEventHandlers" can be used to add to existing event handlers without overwriting anything. Useful for mod compatibility.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

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

Postby Major Cooke » Wed Mar 08, 2017 8:45 pm

Yeah, ZZYZX only recently told me about it himself.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

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

Postby Ed the Bat » Fri Mar 10, 2017 5:55 pm

I had no issue with multiple instances of EventHandlers among different MAPINFO lumps. But I just tried changing them to AddEventHandlers, and now the event handlers never activate. Is there something special I need to do?
User avatar
Ed the Bat
I'm tired. I want to go home.
 
Joined: 03 May 2012
Location: Maryland, US

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

Postby ZZYZX » Fri Mar 10, 2017 6:51 pm

Probably a bug or something.
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 » Wed Mar 22, 2017 4:48 pm

Code: Select allExpand view
class LADgameInputHandler EventHandler
{
    
override void ConsoleProcess(ConsoleEvent e)
    {
        if (
e.Name == 'OpenCharacterMenu')
        {
            
EventHandler.SendNetworkEvent("OpenCharacterMenu"000);
        }
    }

    
override void NetworkProcess(ConsoleEvent e)
    {
        if (
e.Name == 'OpenCharacterMenu')
        {
            
let p players[e.Player].mo;

            if (
p)
            {
                
Menu.SetMenu("ItemDebugMenu");
            }
        }
    }
}
 


Script error, ":zscript/base/ladgameinput/ladgameinput.zc" line 76:
Can't call ui function SetMenu from play context (not readable)

Help?
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

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

Postby Graf Zahl » Wed Mar 22, 2017 5:27 pm

You are trying to open the menu from inside the play simulation. Any reason you are seinding that through the network?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

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

Postby Major Cooke » Wed Mar 22, 2017 6:19 pm

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.)
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests