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
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This function calls registered Remote Prodecure Call (RPC) from browser to client-side and expects a callback.
{{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>
Line 12: Line 15:
*{{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 31:


</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]]

Latest revision as of 18:44, 24 May 2024

Client-Side
Function

 JavaScript




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