BE CAREFUL WITH THIS ERROR IN FIVEM SCRIPTING | SendNUIMessage

It took me a lot of time to figure out what was wrong with the simple code for my FiveM Server.

I just wanted to test a Javascript callback function that gets invoked by the SendNUIMessage function.

First of all, the documentation is wrong about the case of the method. it's actually SendNUIMessage, as I used here in this text and title, and not SendNuiMessage (the letters "ui" are not uppercased in the reference, which is wrong).

The next problem was figuring out what the hell was going on. I haven't yet found a way for the FiveM Server (FXServer?) to show me more error messages, but on the other hand, I have only played around with it for a ~10 hours.

Since coverage for Javascript server & client scripts for FiveM is pretty scarce, you might get more problems than a lua user - simply because there is less help for you out there.

Most tutorials and questions that google comes up with in relation to SendNUIMessage don't cover one important thing: you have to use the JSON serializer!

WRONG:
    var sendMsg = function() {
        SendNuiMessage({text: "Hello, World!"});
    }
This example would never fire a 'message' event to your html and javascript files, and I tried everything, trust me on this one.
RIGHT:
    var sendMsg = function() {
        SendNuiMessage(JSON.stringify({text: "Hello, World!"}));
    }

If you stringify your JSON before sending it, the event will magically trigger. I hope this article was helpful to you, and I hope you enjoy coding your FiveM GTA V server. See you next time!

Kommentare

Beliebte Posts aus diesem Blog

10 Free YouTube Like And Subscribe Button Animations That Will Give You A Headstart On Your Competition

Castlevania-style Axe-Throwing with Gamemaker: Studio