Page 1 of 1

GMCP Events Not Firing

Posted: Fri Feb 05, 2016 6:35 am
by Havastus
I'm trying to test how to handle the GMCP events, yet having a bit of difficulty. From all of the tutorials that I've seen online, I'm doing everything correctly, yet the script isn't firing! Below is the script that I've set up:

i.imgur.com/SdGKVLm.png:

Slysven {Editor} I've included image directly:
Image
However, whenever I try to test this (by just pressing Enter and triggering the gmcp.Char.Vitals event), the script doesn't execute!

Any advice?

Re: GMCP Events Not Firing

Posted: Mon Feb 22, 2016 5:35 am
by tarkenton
Silly question, I know, but have you made sure you turned GMCP on in the settings?

Re: GMCP Events Not Firing

Posted: Mon Feb 22, 2016 12:45 pm
by Havastus
Yes, I made sure to check that before posting it here.

Re: GMCP Events Not Firing

Posted: Thu Mar 03, 2016 10:52 am
by SlySven
I think the display command has to be included in a lua function with that command:

Code: Select all

function gmcp.Chars.vitals()
    display(gmcp.Chars.vitals)
end
Warning: GMCP is not an area I have any experience with so this could easily be wrong... :?

Re: GMCP Events Not Firing

Posted: Thu Mar 03, 2016 4:17 pm
by Havastus
I'll check it out tonight, thanks for replying. My question is, why do I have to surround the display in a function? The Mudlet GMCP documentation makes it seem as if the script will be executed as-is once the given event is raised.

I've been getting around this using the registerAnonymousEventHandler() function, but would rather do so as the examples show.

Re: GMCP Events Not Firing

Posted: Fri Mar 04, 2016 1:20 am
by SlySven
I think it is because functions are stored as identifiable Lua structures which can be accessed by key (their name) the '.' element of the GMCP variable is (I think the term is 'syntactic sugar') also a "sub"-element selector in Lua - so vitals is a function stored as a member of the Chars table which is a member of the gmcp table... and so on up to the top-level _G Lua global table. For the Event system to work it has to register an identifiable function to call for that event - with arguments to pass and I think that needs this wrapping up of things as functions. Again I stress, Lua is not my strongest skill so I could have got it wrong. If anyone else wants to enlighten the pair of us I won't object!