GMCP Events Not Firing

Post Reply
Havastus
Posts: 4
Joined: Thu Nov 19, 2015 2:24 am

GMCP Events Not Firing

Post 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?

tarkenton
Posts: 30
Joined: Thu Feb 07, 2013 7:33 am

Re: GMCP Events Not Firing

Post by tarkenton »

Silly question, I know, but have you made sure you turned GMCP on in the settings?

Havastus
Posts: 4
Joined: Thu Nov 19, 2015 2:24 am

Re: GMCP Events Not Firing

Post by Havastus »

Yes, I made sure to check that before posting it here.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: GMCP Events Not Firing

Post 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... :?

Havastus
Posts: 4
Joined: Thu Nov 19, 2015 2:24 am

Re: GMCP Events Not Firing

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

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: GMCP Events Not Firing

Post 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!

Post Reply