Browser::callProc: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{ClientsideJsFunction}} | {{ClientsideJsFunction}} | ||
__TOC__ | __TOC__ | ||
<br/> | <br/> | ||
{{JSContainer| | {{JSContainer| | ||
This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback. | |||
== Syntax == | == Syntax == | ||
<pre> | <pre> | ||
Latest revision as of 18:44, 24 May 2024
Client-Side Function
JavaScript Syntax
This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback.
Syntax
mp.events.callProc('eventProcName', args);
Required Arguments
- *eventProcName: String
- args: Any
Examples
JavaScript Syntax
// calls 'test_proc' from client-side
mp.events.callProc('test_proc', 'test');
Client-Side
mp.events.addProc('test_proc', (text) => {
mp.gui.chat.push('data: ' + text);
});
Example calling an object:
// calls 'test' from client-side
const data = await mp.events.callProc('test');
if (data) {
const {testOne, testTwo} = JSON.parse(data);
}
Client-Side
mp.events.addProc("test", async () => {
return JSON.stringify({
testOne: "whatever",
testTwo: "two",
});
});
See also
- Functions:
- Properies: