-
Notifications
You must be signed in to change notification settings - Fork 121
Accessing and modifying global variables
paulbartrum edited this page Apr 26, 2016
·
4 revisions
In order to interact with a script, it is useful to be able to modify and retrieve the values of global variables.
For example, say we have the following javascript file (c:\test.js):
interop = interop + 5
The following c# code initializes, then outputs the value of the "interop" variable.
var engine = new Jurassic.ScriptEngine();
engine.SetGlobalValue("interop", 15);
engine.ExecuteFile(@"c:\test.js");
Console.WriteLine(engine.GetGlobalValue<int>("interop"));
This code outputs "20" to the console.
Note that you can only set the value of a variable to a supported type.
Next tutorial: Creating objects and arrays