Wanted Posted September 26, 2011 Share Posted September 26, 2011 [sCAR]function WaitFuncEx(Func: string; Parameters: TVariantArray; DesiredResult: Variant; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Variant; var T: LongInt; begin Result := True; T := GetSystemTime + RandomRange(MinTotalWait, MaxTotalWait); while (GetSystemTime < T) do if (CallProc(Func, Parameters) = DesiredResult) then Exit else Wait(RandomRange(MinWait, MaxWait)); Result := False; end;[/sCAR] works great until you need a parameter that is a var For example if you tried to use FindColor the var X, Y would cause a execution error type mismatch. Ignoring it causes a not enough parameters error. Test script [sCAR]function WaitFuncEx(Func: string; Parameters: TVariantArray; DesiredResult: Variant; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Variant; var T: LongInt; begin Result := True; T := GetSystemTime + RandomRange(MinTotalWait, MaxTotalWait); while (GetSystemTime < T) do if (CallProc(Func, Parameters) = DesiredResult) then Exit else Wait(RandomRange(MinWait, MaxWait)); Result := False; end; var P: TPoint; begin FindColor(P.X, P.y, 12312554, 668, 15, 670, 17); WaitFuncEx('FindColor', [P.X, P.Y, 12312554, 668, 15, 670, 17], True, 100, 250, 90000, 120000); end.[/sCAR] Execution Error Line 8 invalid typecast Quote Link to comment Share on other sites More sharing options...
KingKong Posted September 27, 2011 Share Posted September 27, 2011 I found a few errors, though im not sure if thats PS or the compiler itself, but if you comment out line 19 you would get 'Execution Error Line 8 Unknown procedure'. If you try to use CallProc with inbuilt functions/procedures you will get unknown procedure error as above, but if you use CallProc with your own functions/procs it will work but you have to declare the parameters explicitly as TvariantArray. Also CallProc won't return anything(actually it returns nothing) but in simba it returns the correct thing, so think its the compiler's fault? If you don't get what i mean, run this in simba and scar and you'll see: [scar] program New; var v, v1: TVariantArray; res: variant; procedure Add(n1, n2: Integer); //procedure Add(var n1: Integer; var n2: Integer); <<<this also works, so the error is not due to the adding var begin res := n1+n2; end; function equal(n1, n2: Integer):boolean; begin if n1 = n2 then Result:= True else Result:= False; end; begin ClearDebug; v:= [1, 1]; //CallProc('Add', [1, 1]); <<<<<<This wont work CallProc('Add', v); //<<<<<<but this will writeln(CallProc('equal', v)); end. [/scar] Quote Link to comment Share on other sites More sharing options...
FHannes Posted September 27, 2011 Share Posted September 27, 2011 I don't recall exactly, but I believe it requires trhe variant array to be variable. The function is based directly on methods in the script engine though, so I can't promise it would actually function correctly given PascalScript's legendary high performance and low bugcount. Quote Link to comment Share on other sites More sharing options...
KingKong Posted September 27, 2011 Share Posted September 27, 2011 I don't recall exactly, but I believe it requires trhe variant array to be variable. The function is based directly on methods in the script engine though, so I can't promise it would actually function correctly given PascalScript's legendary high performance and low bugcount. Yes it does, but thats not the main problem, CallProc doesn't work for inbuilt functions/procedures(if you get what i mean) and it doesn't return a valid output. Quote Link to comment Share on other sites More sharing options...
FHannes Posted September 27, 2011 Share Posted September 27, 2011 yes, it wouldn't work for built-in functions, because it only calls functions defined in the script. If it doesn't return the corerct output, then I probably can't do anything about that... Quote Link to comment Share on other sites More sharing options...