FabianTerhorst / coreclr-module

Old alt:V CoreClr (.NET Core Common Language Runtime) community made module. New: https://github.com/altmp/coreclr-module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[C# client] `ScriptRPCEvent.WillAnswer` does not work

duydang2311 opened this issue · comments

I'm using WillAnswer in my client RPC event handler but the server somehow gets Answer not handled error.

Alt.OnScriptRPC += async (scriptRpcEvent, name, args, answerId) => {
    scriptRpcEvent.WillAnswer();
    await Task.Delay(1);
    await AltAsync.Do(() => {
        scriptRpcEvent.Answer("OK");
    });
};

You have to call WillAnswer before it spawns a task. So start the task inside none async handler.

If this is correct according to what you said, unfortunately it's still giving Answer not handled error.

Alt.OnScriptRPC += (scriptRpcEvent, name, args, answerId) => {
    scriptRpcEvent.WillAnswer();
    Task.Delay(1).ContinueWith(t => {
        AltAsync.Do(() => {
            scriptRpcEvent.Answer("OK");
        });
    });
};

The scriptRpcEvent is gone before it enters the task. So you can't use it like this.

Can I use Alt.EmitRPCAnswer with answerId instead? I actually use Alt.EmitRPCAnswer instead of scriptRpcEvent in my code, but I don't write it in the reproduction code. Sorry for that.