Scripting:Script editor

From STNE Wiki

(Difference between revisions)
Jump to: navigation, search
 
(4 intermediate revisions not shown)
Line 1: Line 1:
Greetings STNE Community!
Greetings STNE Community!
-
We now have a external script editor and a SDK (client API), with which you will now be able to write and run scripts outside of the browser. The editor or SDK requires  [http://www.microsoft.com/downloads/de-de/details.aspx?FamilyID=5765d7a8-7722-4888-a970-ac39b33fd8ab Microsoft .NET Framework 4.0 Client Profile]
+
We now have a external script editor and a SDK (client API), with which you will now be able to write and run scripts outside of the browser. The editor or SDK requires  [http://www.microsoft.com/download/en/details.aspx?id=17113 Microsoft .NET Framework 4.0 Client Profile]
http://stne.net/download/stne.scripteditor/images/mainwindow.png
http://stne.net/download/stne.scripteditor/images/mainwindow.png
Line 15: Line 15:
* Scripts will be cached locally.
* Scripts will be cached locally.
* Position of the window as well as opened scripts will be automatically restored when restarting the application
* Position of the window as well as opened scripts will be automatically restored when restarting the application
 +
* Code correction and completion while typing.
-
[b]Problems:[/b]
+
'''Problems:'''
* No asyncron requests, which unfortunately causes the application to get stuck for a moment during server communication.
* No asyncron requests, which unfortunately causes the application to get stuck for a moment during server communication.
* New scripts must be created via browser.
* New scripts must be created via browser.
-
[b]Suggestions for improvement are welcome[/b] Please realize though that the editor is no replacement for a real IDE or a text editor (example: Ultra-edit)
+
'''Suggestions for improvement are welcome''' Please realize though that the editor is no replacement for a real IDE or a text editor (example: Ultra-edit)
* [http://stne.net/download/stne.scripteditor/stne.ScriptEditor.setup.zip Download of the ScriptEditor ("setup")] The "Setup" copies the files into a "stne.ScriptEditor" located on the desktop.
* [http://stne.net/download/stne.scripteditor/stne.ScriptEditor.setup.zip Download of the ScriptEditor ("setup")] The "Setup" copies the files into a "stne.ScriptEditor" located on the desktop.
Line 27: Line 28:
Every function which is possible in the editor, also are able to be run by the SDK client. The containing "stne.client.dll" also requires ".NET Framework 4 Client Profile."
Every function which is possible in the editor, also are able to be run by the SDK client. The containing "stne.client.dll" also requires ".NET Framework 4 Client Profile."
-
Furthermore, a code example is contained on how the library is to be used. Here too the captcha is forced, so that no automating happens when the player is not present. The client-API is available in any .NET language, for example; C# or VB.NET. As free development environment there is [http://www.microsoft.com/germany/express/download/default.aspx Microsoft Visual Studio Express 2010] und [http://sharpdevelop.net/opensource/sd/ #Develop]
+
Furthermore, a code example is contained on how the library is to be used. Here too the captcha is forced, so that no automating happens when the player is not present. The client-API is available in any .NET language, for example; C# or VB.NET. As free development environment there is [http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express Microsoft Visual Studio Express 2010] und [http://sharpdevelop.net/opensource/sd/ #Develop]
There is a very important new innovation in the Script-Engine: "Services."  
There is a very important new innovation in the Script-Engine: "Services."  
Line 119: Line 120:
-
[b]Should you have any questions in regards to the  ClientAPI please post in the script forum[/b] I will make sure to take a look at it within the next few days.I
+
'''Should you have any questions in regards to the  ClientAPI please post in the script forum''' I will make sure to take a look at it within the next few days.
Regards
Regards
Arakis
Arakis
 +
[[Category:Scripting]]

Latest revision as of 09:13, 2 May 2020

Greetings STNE Community!

We now have a external script editor and a SDK (client API), with which you will now be able to write and run scripts outside of the browser. The editor or SDK requires Microsoft .NET Framework 4.0 Client Profile

mainwindow.png

Features of the editor Editors:

  • Login
  • Open/Save scripts which are in the player account.
  • Open/Save local cripts
  • Syntax emphasis
  • Code-check and correction
  • Editing of multiple files at the same time (tabs)
  • To prevent timed scripts to run, every 60 minutes a captcha will be queried.
  • Scripts will be cached locally.
  • Position of the window as well as opened scripts will be automatically restored when restarting the application
  • Code correction and completion while typing.

Problems:

  • No asyncron requests, which unfortunately causes the application to get stuck for a moment during server communication.
  • New scripts must be created via browser.

Suggestions for improvement are welcome Please realize though that the editor is no replacement for a real IDE or a text editor (example: Ultra-edit)

Every function which is possible in the editor, also are able to be run by the SDK client. The containing "stne.client.dll" also requires ".NET Framework 4 Client Profile." Furthermore, a code example is contained on how the library is to be used. Here too the captcha is forced, so that no automating happens when the player is not present. The client-API is available in any .NET language, for example; C# or VB.NET. As free development environment there is Microsoft Visual Studio Express 2010 und #Develop

There is a very important new innovation in the Script-Engine: "Services."

Services, like extensions stay "loaded," they will not constantly be compiled and rebooted. "Public" defined function are able to be queried using other scripts. A client could therefore define a entire request, and deposit it in a service script, as a result; the code does not constantly need to be sent, compiled and initialized. In addition to services which are controlled by the client, are able to return any type of variable. Currently resource types and CDataNodeList's are accepted

clientsample.png

Codebeispiel in C#:

TAuthentification auth = new TAuthentification();
auth.Username = username;
auth.Password = password; 

TScriptClient client = new TScriptClient(auth);
client.OnOutputAvailable += OnOutPutAvailable;
client.OnCaptchaNeeded += OnCaptchaNeeded;

client.SetAuthServerUrl(server);

//Example 1: Execute code directly
client.Execute("WriteLine('Hello Universe!');");

//Example 2: Execute code as service and invoke service-method
client.ScriptCacheCode = larneFunctions.StringLoadFromFile("SampleService.ls");
client.ScriptCacheName = "TestService";
//client.ExecuteScript(client.ScriptCode); //Force recompile

client.InvokeMethod("ShowMyShips");

int MyIncrementResult = (int)client.InvokeMethod("MyIncrement", null, 23).CustomResult;
Console.WriteLine(MyIncrementResult);

System.Collections.Hashtable dic = new System.Collections.Hashtable();
dic.Add("n1", 10);
dic.Add("n2", 15);
TExecuteResult er = client.InvokeMethod("MyParameterTest", dic, "arg1", "arg2");
if (er.OK)
{
  Console.WriteLine(er.CustomResult);
  Console.WriteLine(er.CustomValues["r1"]);
  Console.WriteLine(er.CustomValues["r2"]);
  Console.WriteLine(er.CustomValues["r3"]);
  TDataNodeList dnl = (TDataNodeList)er.CustomValues["dnl"];
  Console.WriteLine(dnl.ToString(true));
}

On the server the following script is stored, it must not even be created as a script:

#ServiceName TestService;

ScriptContext.ActivateService();

Public Function MyIncrement(a As Integer) As Integer
{
  WriteLine('MyIncrement called...');
  Return a + 1;
}

Public Function ShowMyShips()
{
  WriteLine('ShowMyShips called...');
  Var enum As New CShipEnumerator();
  While(enum.Next())
  {
    Var ship As CMyShip = enum.CurrentShip;
    WriteLine(ship.ShipID & ' - ' & ship.Name);
  }
}

Public Function MyParameterTest(param1 As String, param2 As String)
{
  WriteLine('MyParameterTest called...');
  ScriptContext.SetResult('Mainresult'); //Is the same like Return
  ScriptContext.SetResult('r1', 'Named result');
  Var n1 As Integer = ScriptContext.GetCustomRequestArgument('n1');
  Var n2 As Integer = ScriptContext.GetCustomRequestArgument('n2');
  ScriptContext.SetResult('r2', n1 + n2);
  ScriptContext.SetResult('r3', param1 & param2);
  
  //CDataNodeList as result is possible!
  Var NodeList As New CDataNodeList();
  NodeList.Add('key1');
  NodeList.Add('key2').Items.Add('subkey');
  ScriptContext.SetResult('dnl', NodeList);
}

WriteLine('service init');

Lastly, every script which is run will be fully stored, as well as any prior versions with player id, ip and date


Should you have any questions in regards to the ClientAPI please post in the script forum I will make sure to take a look at it within the next few days.

Regards Arakis

Personal tools