SRL Archive - Jr. Member General Help and Discussion

Access violation


rj

2014-03-11 17:20:23

I'm using waitFunc:

function WaitFunc(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
exit(true);
Wait(WaitPerLoop);
end;
end;

When I try to use

if waitFunc(@smithingScreen, 40, 4000) then

I get a access violation at line 120, which is the waitFunc, more specifically, this line:

if (Func()) then

I have tried doing it as

if (Func) then

and

if (Func = true) then

with the same results (no pun intended)



The function I am trying to use to wait:

function smithingScreen():boolean;
begin
result := (_317_getInterfaceName = 'What would you like to make?');
end;

[spoiler=interface.simba if needed]
(*
Author: Officer Barbrady
Description: Gets interface TPA
*)

function _317_getInterfaceTPA:TPointArray;
begin
findColorsTolerance(result, 3358536, mainscreen.bounds, 3);
end;

(*
Author: Officer Barbrady
Description: Gets open interface bounds
*)

function _317_getInterfaceBounds:TBox;
begin
result := getTPABounds(_317_getInterfaceTPA);
end;

(*
Author: Officer Barbrady
Description: Returns true if interface is open
*)

function _317_interfaceOpen:boolean;
begin
result := (length(_317_getInterfaceTPA) > 1000);
end;

(*
Author: Officer Barbrady
Description: Gets name of interface
*)

function _317_getInterfaceName:string;
var
b:TBox;
begin
if (not _317_interfaceOpen) then
exit;
b := _317_getInterfaceBounds();
b.y2 := b.y1 + 40;
result := getSimpleText([2070783, 37375, 65535], b.x1, b.y1, b.x2, b.y2, 'upchars07');
end;
[/spoiler]

Not sure what it is :/ Probably something stupid

Kevin

2014-03-11 17:27:10

I think it's how you're calling WaitFunc.

Does your code look like this?
WaitFunc(@smithingscreen, 10, 500);

You NEED the Parenthesis around functions, so I believe it should look like:
WaitFunc(@smithingscreen(), 10, 500);

rj

2014-03-11 17:28:04

From: Kevin
I think it's how you're calling WaitFunc.

Does your code look like this?
WaitFunc(@smithingscreen, 10, 500);

You NEED the Parenthesis around functions, so I believe it should look like:
WaitFunc(@smithingscreen(), 10, 500);


Not in lape, () is to invoke it, not using the () is to pass it to the function

riwu

2014-03-11 18:36:40

I tested w/o parenthesis and it works fine for me w/o any errors?
Try the following:

function WaitFunc(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
exit(true);
Wait(WaitPerLoop);
end;
end;

function smithingScreen: boolean;
begin
end;

begin
waitFunc(@smithingScreen, 40, 4000);

try
waitFunc(@smithingScreen(), 40, 4000);
writeln('success');
except
writeln('error occurs when using parenthesis');
end;
end.

rj

2014-03-11 19:53:35

From: riwu
I tested w/o parenthesis and it works fine for me w/o any errors?
Try the following:

function WaitFunc(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
exit(true);
Wait(WaitPerLoop);
end;
end;

function smithingScreen: boolean;
begin
end;

begin
waitFunc(@smithingScreen, 40, 4000);

try
waitFunc(@smithingScreen(), 40, 4000);
writeln('success');
except
writeln('error occurs when using parenthesis');
end;
end.


You have to use it without parenthesis -.- if you try it with them it's a whole different error (cannot invoke identifier)

riwu

2014-03-12 06:29:50

From: Officer Barbrady
You have to use it without parenthesis -.- if you try it with them it's a whole different error (cannot invoke identifier)

Yeah i tried it w/o parenthesis and it gave no error.

With parenthesis it gives an Access violation.

Post a screenshot of your result?

Brandon

2014-03-12 08:21:09

GetSimpleText OR GetInterfaceTPA is throwing..
Never saw anyone take the address of result or pass it by reference before :S

Either way, one of those are failing.. You need to debug your code and start printing stuff out.

rj

2014-03-12 15:19:19

From: Brandon
GetSimpleText OR GetInterfaceTPA is throwing..
Never saw anyone take the address of result or pass it by reference before :S

Either way, one of those are failing.. You need to debug your code and start printing stuff out.


It seems that I'm able to do

if waitFunc(@_317_interfaceOpen, 40, 4500) then

which is fine because I doubt some other random interface is going to open :/