Scripting:Script editor
From STNE Wiki
m |
|||
Line 17: | Line 17: | ||
* Code correction and completion while typing. | * Code correction and completion while typing. | ||
- | + | '''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. |
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
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)
- Download of the ScriptEditor ("setup") The "Setup" copies the files into a "stne.ScriptEditor" located on the desktop.
- Download of the ScriptEditor (complete)
- Download of the client SDK (incl. example and full source code of the script editor.)
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
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