Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
duydang2311 opened this issue Jan 3, 2024 · 4 comments
Open

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

duydang2311 opened this issue Jan 3, 2024 · 4 comments

Comments

@duydang2311
Copy link
Contributor

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");
    });
};
@FabianTerhorst
Copy link
Owner

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

@duydang2311
Copy link
Contributor Author

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

@FabianTerhorst
Copy link
Owner

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

@duydang2311
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants