Cuberite Forum

Full Version: cRoot not working for some reason.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there, I just started messing around with plugin making for cuberite, and cRoot doesent seem to be working.

The code in question is:
Code:
cRoot:BroadcastChat(cCompositeChat()
    :AddTextPart(Player:GetName(), "@e")
    :AddTextPart(": ", "@f")
    :AddTextPart(Message)
    :SetMessageType(mtCustom)
)

And the error is:
Code:
[17:49:46] LUA: Plugins\ChatFormatter/main.lua:15: error in function 'BroadcastChat'.
     argument #1 is 'class cRoot'; 'cRoot' expected.

[17:49:46] Stack trace:
[17:49:46]   [C](-1): BroadcastChat
[17:49:46]   Plugins\ChatFormatter/main.lua(15): (no name)
[17:49:46] Stack trace end
[17:49:46] Error in <attached> calling function <callback>()

I hope you guys can solve my issue. Thanks!
Hi, welcome to the forum! Smile

Only functions marked as 'STATIC' can be called directly. For the other functions you have to call it from a cRoot instance which can be easily retrieved using the cRoot:Get() function. So in the end your code would look like this:

cRoot:Get():BroadcastChat(cCompositeChat()
    :AddTextPart(Player:GetName(), "@e")
    :AddTextPart(": ", "@f")
    :AddTextPart(Message)
    :SetMessageType(mtCustom)
)
TYSM it worked! And thanks for the welcome, I hope I can become better and not have to post on here every day.
Don't wory about asking questions. You wouldn't believe the questions I asked when I started here back in 2011. Smile