runJsFunction: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Created page with "{{stub}} {{Experimental}} {{MacroFunction |name=runJSfunction |description= Runs a JavaScript function which is defined in a frame5, dialog5, or overlay. |usage= <source lang...")
 
m (Conversion script moved page RunJsFunction to runJsFunction: Converting page titles to lowercase)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{stub}}
{{Experimental}}
{{Experimental}}
{{MacroFunction
{{MacroFunction
|name=runJSfunction
|name=runJSfunction
|version=1.8.0
|description=
|description=
Runs a JavaScript function which is defined in a frame5, dialog5, or overlay.
Runs a JavaScript function which is defined in a frame5, dialog5, or overlay.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
runJSfunction(name, type, func, thisArg, argsArray)
runJSfunction(name, type, func, thisArg, argsArray)
</syntaxhighlight>


</source>
'''Parameter'''
'''Parameter'''
{{param|name |Name of an active frame, dialog, or overlay.}}
{{param|name|Name of an active frame, dialog, or overlay.}}
{{param|type|Either "frame", "dialog", or "overlay".}}
{{param|type|Either "frame", "dialog", or "overlay". This is needed because a frame, a dialog and an overlay could all share the same name, in which case it is not clear which component is the target.}}
{{param|thisArg|Value of "this" provided to the function.}}
{{param|func|Name of the JavaScript function to run.}}
{{param|thisArg|Value of "this" provided to the function. Should be "null" or the name of a variable already defined in the script.}}
{{param|argsArray|JSON array specifying the arguments with which the JavaScript function should be called.}}
{{param|argsArray|JSON array specifying the arguments with which the JavaScript function should be called.}}


|examples=
|examples=
Changing info displayed on the frame by passing a JSON {{code|argsArray}} to the function {{code|changeHP}}.
<syntaxhighlight lang="mtmacro" line>
[frame5("Test 1"):{
<script>
[r: "function changeHP(hp) { document.getElementById('hp').innerHTML = hp;}"]
</script>
Hitpoints: <span id="hp">10</span>
}]
</syntaxhighlight>


|also=
Call the {{code|changeHP}} Javascript function.
<syntaxhighlight lang="mtmacro" line>
[r: runJsFunction("Test 1", "frame", "changeHP", "null", json.append("[]", "3"))]
</syntaxhighlight>
 
Using {{code|thisArg}} in call to {{code|alertFullName}}.
<syntaxhighlight lang="mtmacro" line>
[frame5("Test 2"):{
<script>
[r: 'function alertFullName() { alert("Full Name: " + this.firstName + " " + this.lastName);}']
var person = [r: json.set("{}", "firstName", "John", "lastName", "Smith")];
document.write("<b>First Name:</b> " + person.firstName + "<br/><b>Last Name</b>: " + person.lastName + "<br/>");
</script>
}]
</syntaxhighlight>
 
Call {{code|alertFullName}} and specify the Javascript variable {{code|person}}.
<syntaxhighlight lang="mtmacro" line>
[r: runJsFunction("Test 2", "frame", "alertFullName", "person")]
</syntaxhighlight>


}}
}}

Latest revision as of 23:42, 9 February 2023

 This article describes a feature or macro function that is experimental and may be subject to change.

runJSfunction() Function

Introduced in version 1.8.0
Runs a JavaScript function which is defined in a frame5, dialog5, or overlay.

Usage

runJSfunction(name, type, func, thisArg, argsArray)

Parameter

  • name - Name of an active frame, dialog, or overlay.
  • type - Either "frame", "dialog", or "overlay". This is needed because a frame, a dialog and an overlay could all share the same name, in which case it is not clear which component is the target.
  • func - Name of the JavaScript function to run.
  • thisArg - Value of "this" provided to the function. Should be "null" or the name of a variable already defined in the script.
  • argsArray - JSON array specifying the arguments with which the JavaScript function should be called.

Examples

Changing info displayed on the frame by passing a JSON argsArray to the function changeHP.
[frame5("Test 1"):{
<script>
[r: "function changeHP(hp) { document.getElementById('hp').innerHTML = hp;}"]
</script>
Hitpoints: <span id="hp">10</span>
}]

Call the changeHP Javascript function.

[r: runJsFunction("Test 1", "frame", "changeHP", "null", json.append("[]", "3"))]

Using thisArg in call to alertFullName.

[frame5("Test 2"):{
<script>
[r: 'function alertFullName() { alert("Full Name: " + this.firstName + " " + this.lastName);}']
var person = [r: json.set("{}", "firstName", "John", "lastName", "Smith")];
document.write("<b>First Name:</b> " + person.firstName + "<br/><b>Last Name</b>: " + person.lastName + "<br/>");
</script>
}]

Call alertFullName and specify the Javascript variable person.

[r: runJsFunction("Test 2", "frame", "alertFullName", "person")]