/// <summary> /// Call script function with delay or skip with no error if function not exists. /// </summary> /// <param name="funcName">Function name.</param> /// <param name="timeout">Delay in seconds before calling function.</param> /// <param name="param1">Optional parameter to function.</param> /// <param name="param2">Optional parameter to function.</param> /// <param name="param3">Optional parameter to function.</param> /// <param name="param4">Optional parameter to function.</param> public void CallFunctionWithDelayOrSkip(string funcName, float timeout, ScriptVar?param1 = null, ScriptVar?param2 = null, ScriptVar?param3 = null, ScriptVar?param4 = null) { if (!_vm.IsFunctionExists(funcName)) { return; } CallFunctionWithDelay(funcName, timeout, param1, param2, param3, param4); }
/// <summary> /// Call script function. /// </summary> /// <returns>Execution error.</returns> /// <param name="funcName">Function name.</param> /// <param name="result">Result of function execution.</param> /// <param name="param1">Optional parameter to function.</param> /// <param name="param2">Optional parameter to function.</param> /// <param name="param3">Optional parameter to function.</param> /// <param name="param4">Optional parameter to function.</param> public string CallFunction(string funcName, out ScriptVar result, ScriptVar?param1 = null, ScriptVar?param2 = null, ScriptVar?param3 = null, ScriptVar?param4 = null) { var undef = new ScriptVar(); if (InFunctionCall) { result = undef; return("already in function call"); } if (!_parser.Vars.IsFunctionExists(funcName)) { result = undef; return(string.Format("function '{0}' not found", funcName)); } InFunctionCall = true; var func = _parser.Vars.GetFunction(funcName); _scanner.PC = func.Pc; _parser.Vars.ResetVars(); var id = 0; var max = func.Params != null ? func.Params.Length : 0; if (param1 != null && id < max) { // ReSharper disable once PossibleNullReferenceException _parser.Vars.RegisterVar(func.Params[id++], param1.Value); } if (param2 != null && id < max) { // ReSharper disable once PossibleNullReferenceException _parser.Vars.RegisterVar(func.Params[id++], param2.Value); } if (param3 != null && id < max) { // ReSharper disable once PossibleNullReferenceException _parser.Vars.RegisterVar(func.Params[id++], param3.Value); } if (param4 != null && id < max) { // ReSharper disable once PossibleNullReferenceException _parser.Vars.RegisterVar(func.Params[id++], param4.Value); } for (; id < max; id++) { // ReSharper disable once PossibleNullReferenceException _parser.Vars.RegisterVar(func.Params[id], undef); } var err = _parser.CallFunction(); result = _parser.RetVal; InFunctionCall = false; return(err); }
/// <summary> /// Call script function or skip with no error if function not exists. /// </summary> /// <returns>Execution error.</returns> /// <param name="funcName">Function name.</param> /// <param name="result">Result of function execution.</param> /// <param name="param1">Optional parameter to function.</param> /// <param name="param2">Optional parameter to function.</param> /// <param name="param3">Optional parameter to function.</param> /// <param name="param4">Optional parameter to function.</param> public string CallFunctionOrSkip(string funcName, out ScriptVar result, ScriptVar?param1 = null, ScriptVar?param2 = null, ScriptVar?param3 = null, ScriptVar?param4 = null) { if (!_vm.IsFunctionExists(funcName)) { result = new ScriptVar(); return(null); } return(_vm.CallFunction(funcName, out result, param1, param2, param3, param4)); }
/// <summary> /// Call script function with delay. /// </summary> /// <param name="funcName">Function name.</param> /// <param name="timeout">Delay in seconds before calling function.</param> /// <param name="param1">Optional parameter to function.</param> /// <param name="param2">Optional parameter to function.</param> /// <param name="param3">Optional parameter to function.</param> /// <param name="param4">Optional parameter to function.</param> public void CallFunctionWithDelay(string funcName, float timeout, ScriptVar?param1 = null, ScriptVar?param2 = null, ScriptVar?param3 = null, ScriptVar?param4 = null) { var pair = new TimeoutPair { Event = funcName, Time = Time.time + timeout, Param1 = param1, Param2 = param2, Param3 = param3, Param4 = param4 }; _timeoutListeners.Add(pair); }
ScriptVar ApiCallWithDelay(ScriptVm vm) { var count = vm.GetParamsCount(); var pTimeout = vm.GetParamById(0); var pEvent = vm.GetParamById(1); if (count < 2 || !pTimeout.IsNumber || !pEvent.IsString) { _vm.SetRuntimeError("(nTimeout, sFuncName[, param1, param2]) parameters required"); return(new ScriptVar()); } ScriptVar?param1 = null; if (count > 2) { param1 = vm.GetParamById(2); } ScriptVar?param2 = null; if (count > 3) { param2 = vm.GetParamById(3); } ScriptVar?param3 = null; if (count > 4) { param3 = vm.GetParamById(4); } ScriptVar?param4 = null; if (count > 5) { param4 = vm.GetParamById(5); } CallFunctionWithDelay(pEvent.AsString, pTimeout.AsNumber, param1, param2, param3, param4); return(new ScriptVar()); }
/// <summary> /// Call script function. /// </summary> /// <returns>Execution error.</returns> /// <param name="funcName">Function name.</param> /// <param name="result">Result of function execution.</param> /// <param name="param1">Optional parameter to function.</param> /// <param name="param2">Optional parameter to function.</param> /// <param name="param3">Optional parameter to function.</param> /// <param name="param4">Optional parameter to function.</param> public string CallFunction(string funcName, out ScriptVar result, ScriptVar?param1 = null, ScriptVar?param2 = null, ScriptVar?param3 = null, ScriptVar?param4 = null) { return(_vm.CallFunction(funcName, out result, param1, param2, param3, param4)); }