Forst of all, props to the great work on the framework!!!
Second, I’m using the Script Editor to run a couple of different bots. Now, they are using a couple of functions that I have to repeat on each file. Is there a way to load an external file with these functions? The #include is only for old-man-C and I can’t use namespaces on scripts. Is there a way to do this?
This module file will keep all my generic/global functions to reuse in all my scripts. So for example, I have a function that outputs a message, sleeps a bit and then refreshes the memory variable. Store it in “c:\functions.cs” as:
Host.Log("sleeping for a bit then reading values after I've slept");
Measurement = Sanderling?.MemoryMeasurementParsed?.Value;
Withing the main script inside the Script Engine Interface I will have the code that loads this file alongside the normal bot code. For example:
var fileAsText = System.IO.File.ReadAllText(@"C:\test.cs");
The issue is that the Script Engine will not recognize that the “sleep” function exists because it is loaded in the fileAsText variable and not actually parsed to the engine and applied to any context so the Script Interface will trigger an error like:
"CaptionString": "System.Exception: compilation error: (3,1): error CS0103: The name 'sleep' does not exist in the current context\r\n at BotSharp.ScriptRun.ScriptRun.<>c__DisplayClass61_0.<Start>b__0()",
For this case, I would suggest another approach:
Instead of loading test.cs while the script is running, decide what should be in there before starting the script.
You can then remove the statement to load the file from the script and instead drop the functions.cs from windows explorer into the script editor on that location.
This way, the sleep function will become available for use in other parts of the script.