cRoot not working for some reason.
#1
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!
Reply
Thanks given by:
#2
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)
)
Reply
Thanks given by:
#3
TYSM it worked! And thanks for the welcome, I hope I can become better and not have to post on here every day.
Reply
Thanks given by:
#4
Don't wory about asking questions. You wouldn't believe the questions I asked when I started here back in 2011. Smile
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)