As the Scripting Core Suggestions thread is no longer being monitored by EnEsCe, I thought it would be appropriate to post here. I've been messing with exceptions a bit more recently in Soldat Scripting Core, and never really found a use for:
function ExceptionProc(): cardinal;
But the function FunctionName could make ExceptionProc become of some use.
Suggested function declaration:
function FunctionName(const FuncId: cardinal): string;
But when I was making an example to share, I found that another function, FunctionExists, may be of use, although not completely necessary since CrossFunc does not spew errors when invoking a function which does not exist, but can still be of use for other reasons (such as debug code for '/invoke <funcname> <params...>' admin command).
Suggested function declaration:
function FunctionExists(const FuncName: string): boolean;
Example usage:
try
DoActionOne();
DoActionTwo();
DoActionThree();
except
WriteLn('Exception caught while processing ''' + FunctionName(ExceptionProc()) + '''');
if (FunctionExists({ScriptName + '.' + }FunctionName(ExceptionProc()) + 'ErrorHandler') then
CrossFunc(ScriptName + '.' + FunctionName(ExceptionProc()) + 'ErrorHandler'));
end;
For FunctionExists support of multiple scripts, maybe rather:
function CrossFuncExists(const FuncName: string): boolean;
or just allowing the commented part in the example code.
EDIT1:
Realized a ScriptExists function would be useful.
function ScriptExists(const Script: string): boolean;
const
ScriptVersion = 1;
procedure ActivateServer();
begin
if (ScriptExists('update')) then
CrossFunc([ScriptName, ScriptVersion], 'update.checkupdate');
end;
Although may want to instead of ActivateServer create a new event for when server first starts (not script) so the update service is not spammed if person recompiles a million times or something. This is just theoretical as of now. (A OnServerStart event would be nice so the workaround wouldn't be necessary, checking if CurrentMap = '' when server first starts)
EDIT2:
As I was thinking of usages of these functions, having a ServerScripts function would be nice so a script has a list of all other scripts.
function ServerScripts(): array of string;
procedure ActivateServer();
var
i: byte;
Scripts: array of string;
begin
Scripts := ServerScripts();
for i := 0 to GetArrayLength(Scripts) - 1 do
if (FunctionExists(Scripts[i] + '.RegisterMaster')) then
CrossFunc([ScriptName], Scripts[i] + '.RegisterMaster');
end;