vassilych / cscs

CSCS: Customized Scripting in C#
MIT License
169 stars 49 forks source link

CSCS Unity integration #29

Open Maximilian-Winter opened 2 years ago

Maximilian-Winter commented 2 years ago

Hello, I really like your idea of a custom language and I have tried to integrate cscs in unity, the way described in your article. But I have some problems getting my code running. the following code:

class MyMessageBusCallbackClass
{
    MyMessageBusCallbackClass(gameApiProxy)
    {
        m_messageBusProxy = gameApiProxy.GetMessageBusProxy();
    }

    function ReceiveMessage()
    {
        messageQueue = m_messageBusProxy.GetMessageQueue(this, "WelcomeMessage");
        welcomeMessage = messageQueue.DequeueMessage();

        DebugLog("Callback from Message Bus: " + welcomeMessage.WelcomeMessage);
    }
}
GameApiProxy = CreateGameApiProxyObject();
MessageBusProxy = GameApiProxy.GetMessageBusProxy();

MyMessageBusCallback = new MyMessageBusCallbackClass(GameApiProxy);

MessageBusProxy.SubscribeToMessage("MyMessageBusCallback", "WelcomeMessage");

Doesnt work as I thought it would. The global Message bus proxy works as intented but the "this" keyword and the message bus proxy in the class doesnt seem to work. The Function "GetMessageQueue" doesnt get founded. Any idea why? When I use the global "MessageBusProxy" It works.

Maximilian-Winter commented 2 years ago

I managed to get the code running. But I think you have a problem with your GetVariable Function in ParserFunction.cs it compares the lowercase name to the normal case variable on the stack and doesn't find it. And the "this" operator only returns an empty array instead of the current class instance. I fixed that also. Now my code runs.

Maximilian-Winter commented 2 years ago

Here is my code with the fixed code. https://github.com/Maximilian-Winter/CSCS-Unity