You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ScriptRunningMachine srm = new ScriptRunningMachine();
srm.WorkMode |= MachineWorkMode.AllowDirectAccess;
Using DirectAccess
Assume that we have a class in .Net as below:
public class User
{
private string nickname = "no name";
public string Nickname
{
get { return nickname; }
set { nickname = value; }
}
public void Hello()
{
MessageBox.Show(string.Format("Hello {0}!", nickname));
}
}
This User class contains a public property Nickname and a public method Hello, we trying to access this property and call the function in script.
In this demo we create the instance of User class in .Net and put it into script context: (instance can also be created in script, see import keyword.
srm.SetGlobalVariable("guest", new User());
An object named guest was be created and added into script, so now we can use this object:
guest.nickname = 'player1';
guest.hello();
When this script executed, a message box will be displayed.