Cuberite Forum
cRoot not working for some reason. - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: cRoot not working for some reason. (/thread-3334.html)



cRoot not working for some reason. - williamist0 - 01-30-2021

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!


RE: cRoot not working for some reason. - NiLSPACE - 01-30-2021

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)
)



RE: cRoot not working for some reason. - williamist0 - 01-30-2021

TYSM it worked! And thanks for the welcome, I hope I can become better and not have to post on here every day.


RE: cRoot not working for some reason. - NiLSPACE - 01-30-2021

Don't wory about asking questions. You wouldn't believe the questions I asked when I started here back in 2011. Smile