coreclr-module icon indicating copy to clipboard operation
coreclr-module copied to clipboard

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

Open duydang2311 opened this issue 1 year ago • 4 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");
    });
};

duydang2311 avatar Jan 03 '24 16:01 duydang2311

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

FabianTerhorst avatar Jan 03 '24 16:01 FabianTerhorst

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");
        });
    });
};

duydang2311 avatar Jan 03 '24 16:01 duydang2311

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

FabianTerhorst avatar Jan 03 '24 16:01 FabianTerhorst

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.

duydang2311 avatar Jan 03 '24 16:01 duydang2311