Browser::callProc: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback. __TOC__ <br/> {{JSContainer| == Syntax == <pre> mp.events.callP...")
 
No edit summary
Line 1: Line 1:
{{ClientsideJsFunction}}
This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback.
This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback.
__TOC__
__TOC__
Line 12: Line 13:
*{{Required}}'''eventProcName''': {{RageType|String}}
*{{Required}}'''eventProcName''': {{RageType|String}}
*'''args''': {{RageType|Any}}
*'''args''': {{RageType|Any}}
 
}}
== Examples ==
== Examples ==
 
{{JSContainer|
<pre>
<pre>
// calls 'test_proc' from client-side
// calls 'test_proc' from client-side
Line 28: Line 29:


</pre>
</pre>
}}
Example calling an object:
<syntaxhighlight lang="javascript">
// calls 'test' from client-side
const data = await mp.events.callProc('test');
if (data) {
  const {testOne, testTwo} = JSON.parse(data);
}
</syntaxhighlight>
{{ClientsideCode|
<syntaxhighlight lang="javascript">
mp.events.addProc("test", async () => {
  return JSON.stringify({
    testOne: "whatever",
    testTwo: "two",
  });
});
</syntaxhighlight>
}}
}}
}}
}}
==See also==
{{Browser_definition_c}}
[[Category:Clientside API]]

Revision as of 18:43, 24 May 2024

Client-Side
Function

 JavaScript



This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback.


JavaScript Syntax

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