SRL Archive - OSR Help

[RESOLVED] Error: Null Pointer Exception


Coh3n

2011-05-17 08:50:39

This came up in MSI the other day. Was reported here. I can't for the life of me figure out why it happens. Was hoping someone here could help. :)

Error:

[0:00:42]: [ ] ---- MSI_FindObjectsIn [27, 28, 25]
[0:00:42]: [ ] -------- No colors found!
[0:00:43]: [ ] -------- Not high enough level for object: Adamantite
Error: Null Pointer Exception at line 1728
Line 1728 is:

with MSI_Objects[Objs[II]] do
Basically, the loop is supposed to continue if the player doesn't have a high enough level to auto that particular object, but for whatever reason, this error occurs every time. I didn't even know you could get this error in PS, so it's even more confusing to me.

Here's the entire MSI_FindObjectsIn procedure:

Function MSI_FindObjectsIn(Objs: TIntegerArray; Var IndexFound: Integer; SearchBox: TBox; Action: fnct_ActionOptions): Boolean;
Var
TPA, TmpTPA: TPointArray;
TheOptions, UpTexts: TStringArray;
I, II, III, HH, HHH, Hi, J, c: Integer;
CheckUpText, inBadBox: Boolean;
Begin
if (not LoggedIn) then
Exit;

MSI_AddHeader('MSI_FindObjectsIn ' + ToStr(Objs));

Hi := High(Objs);

SetLength(TheOptions, Hi + 1);
SetLength(UpTexts, Hi + 1);
For I := 0 To Hi Do
Begin
UpTexts[I] := MSI_Objects[Objs[I]].UpText;
TheOptions[I] := MSI_Objects[Objs[I]].Option;
End;

For II := 0 To Hi Do
With MSI_Objects[Objs[II]] Do // <---- HERE!
begin
// Check the players level; if not high enough, skip object
if (MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript].Name].SkillConst <> SKILL_NONE) then
if (MSI_Players[CurrentPlayer].ReportInfo.SkillLevels[CurrentScript] < MSI_Objects[Objs[II]].Level) then
begin
if (ii = hi) then
MSI_Players[CurrentPlayer].ReportInfo.FalseReason := 'Skill requirement not met';

MSI_Debug('Not high enough level for object: ' + MSI_Objects[Objs[II]].Name);
Continue;
end;

If MSI_FindObjectsTPA(TmpTPA, Objs[II], SearchBox) Then
Begin
// If set to, the script will click the closest object (this negates Priority)
if (MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript].Name].ClickClosest) then
begin
MSI_Debug('Clicking closest object to player');

for i := 0 to High(Objs) do
if (MSI_FindObjectsTPA(TmpTPA, Objs[i], SearchBox)) then
begin
//Writeln('Obj'+IntToStr(i));
TPA := CombineTPA(TPA, TmpTPA);
end;

SortTPAFrom(TPA, Point(MSCX, MSCY));
end else
TPA := TmpTPA;

HH := Min((Tries - 1), High(TPA));
MSI_Debug(IntToStr(Length(TPA))+' objects found!');

For I := 0 to HH Do
Begin
// Check to see if the point is in a bad box
if (Length(NotBoxes) > 0) then
for j := 0 to High(NotBoxes) do
if (PointInBox(TPA[i], NotBoxes[j])) then
begin
MSI_Debug('Point in bad box');
inBadBox := True;
Break;
end;

if (inBadBox) then
Continue;

X := TPA[I].X;
Y := TPA[I].Y;
IndexFound := II;

If (Action = Nothing) Then
Begin
Result := True;
MSI_CloseHeader('MSI_FindObjectsIn: ' + BoolToStr(Result));
NotBoxes := [];
Exit;
End;

HHH := High(UpTexts);
CheckUpText := True;
For III := 0 To HHH Do
If (UpTexts[III] = '') Then
Begin
CheckUpText := False;
Break;
End;

MMouse(TPA[I].X, TPA[I].Y, 2, 2);
Wait(20 + Random(50));

If CheckUpText Then
if (waitUptext(name, 200) and (not RightClickOnly)) then
begin
MSI_Debug('Found ground item');
c := invCount();
getMousePos(x, y);
mouse(x, y, 0, 0, true);
wait(randomRange(1000, 2000));
MSI_CloseHeader('MSI_FindObjectsIn: ' + BoolToStr(Result));
notBoxes := [];
exit;
end else
if (WaitUpTextMulti(UpTexts, 150 + Random(20))) then
begin
MSI_Debug('Uptext found!');
Result := True;
end else begin
SetLength(notBoxes, Length(notBoxes) + 1);
notBoxes[High(notBoxes)] := MSI_MakeBox(Point(TPA[I].X, TPA[I].Y), (W / 2), (H / 2));
end
Else
Result := True;

If (Action = Move) Then
begin
MSI_CloseHeader('MSI_FindObjectsIn: ' + BoolToStr(Result));
NotBoxes := [];
Exit;
end;

If Result Then
Begin
GetMousePos(X, Y);

If (RightClickOnly) Or InRange(Random(100), 0, 10) Or (Action = ClickRight) Then
Begin
Mouse(X, Y, 0, 0, False);
If (Action = ClickRight) or (Action = ClickLeft) Then
Result := (WaitOptionMulti(TheOptions, 750 + Random(100)) or waitOption('ake', 200))
Else
Result := DidClick(True, 1200);
End Else Begin
Mouse(X, Y, 0, 0, True);
Result := DidClick(True, 1200); ;
End;

if (result) then
if ((waitToMove) and (track)) then
MSI_TrackObject(objs[ii])
else
if (waitToMove) then
flag
else
if (track) then
MSI_TrackObject(objs[ii]);

MSI_CloseHeader('MSI_FindObjectsIn: ' + BoolToStr(Result));
NotBoxes := [];
Exit;
End Else Begin
MSI_FindRandoms(True);
MSI_Debug('Uptext didn''t match!');
End;
End;
End;
end;

MSI_CloseHeader('MSI_FindObjectsIn: ' + ToStr(Result));
MSI_FindRandoms(True);
End;
Any help is greatly appreciated.

Thanks,
Cohen

Smidqe

2011-05-17 09:38:42

UpTexts := MSI_Objects[Objs].UpText;
TheOptions := MSI_Objects[Objs].Option;


There's one square bracket too much on Obsj], atleast I think that's the problem. :)
It should be [II].

HyperSecret

2011-05-17 09:48:30

From: Smidqe
There's one square bracket too much on Obsj], atleast I think that's the problem. :)
It should be [II].


Sorry nope.

What exactly is MSI_Objects?

Coh3n

2011-05-17 09:48:48

From: Smidqe
There's one square bracket too much on Obsj], atleast I think that's the problem. :)
It should be [II].

No, that part's right. It's because the Objs[II] is enclosed in MSI_Objects[]. That's what the second ']' is for. :)

Smidqe

2011-05-17 09:50:23

Oops.. How did I miss that, nevermind then. :duh:

Brandon

2011-05-17 10:15:00

:S As far as I know, Square brackets indicate arrays.. you cant place an array inside an array.. and I dont even think simba supports multidimensional arrays or an array of arrays.. the way to do this would probably be:


var
k: Integer;

begin
k:= Objs[II];

For k := 0 To Hi Do
With MSI_Objects[k] Do

end;

Something like that.. Im not good with simba stuff so I dont know how to pass the values of the array into MSI_Objects.. You can always try circle brackets like MSI_Objects[(Objs[II])]

Coh3n

2011-05-17 10:17:05

It supports multi-dimensional arrays. ;) I've used 4D arrays before. You gave me an idea though, thanks. :)

E: Also. that procedure worked great until I added the part that continues if the player didn't have a high enough skill level.

Gu3st...

2011-05-17 10:28:01

Try doing
For II := 0 To Hi Do
begin
WriteLn(ToStr(II));
with MSI_Objects...
instead of
For II := 0 To Hi Do
with MSI_Objects...
and see what II is right before the error occurs.

Markus

2011-05-17 10:49:02

Simba has borked line numbers, you can't really trust those..

Coh3n

2011-05-17 11:12:56

From: Markus
Simba has borked line numbers, you can't really trust those..

I thought that was fixed. I haven't actually had that issue for a very long time (unless this is one of those cases).

Coh3n

2011-05-17 11:28:31

From: Zyt3x
Try doing
For II := 0 To Hi Do
begin
WriteLn(ToStr(II));
with MSI_Objects...
instead of
For II := 0 To Hi Do
with MSI_Objects...
and see what II is right before the error occurs.

Interesting..

[0:01:31]: [ ] ---- MSI_FindObjectsIn [28, 25, 27]
[0:01:31]: 0
[0:01:31]: [ ] ------ Not high enough level for object: Adamantite
Error: Exception: Type Mismatch at line 1729
Says the Type Mismatch is on the Writeln() that was just added.

E: Also tried assigning a variable to Objs[II] and got the same thing.

Brandon

2011-05-17 11:47:47

Hmm Thats odd but could it be that II has no value?? Though I see II Increasing until Hi?? So maybe Hi = 0.. Hi doesnt have a value then?


For II:= 0 to Hi Do
begin
writeln('II: ' + intostr(II)); //<-- doesnt it need the Int part or Tostr?
Writeln('Hi: ' + intostr(Hi));
end;
That should print the values of II and HI everytime it loops through.. if it says 0 then you know that either II or HI was never assigned any values.. which means HI = 0 because it is looping from 0 to 0.. thats not an increase at all..

Does that make sense?? :S Kinda hard for me to explain my thoughts lol

Gu3st...

2011-05-17 11:56:46

From: Coh3n
Interesting..

[0:01:31]: [ ] ---- MSI_FindObjectsIn [28, 25, 27]
[0:01:31]: 0
[0:01:31]: [ ] ------ Not high enough level for object: Adamantite
Error: Exception: Type Mismatch at line 1729
Says the Type Mismatch is on the Writeln() that was just added.

E: Also tried assigning a variable to Objs[II] and got the same thing.
Hm. I didn't expect that one :confused:

Try adding WriteLn(ToSTr(II)); after "MSI_Debug('Not high enough level for object: ' + MSI_Objects[Objs[II]].Name);"

Coh3n

2011-05-17 13:00:54

From: ggzz
Hmm Thats odd but could it be that II has no value?? Though I see II Increasing until Hi?? So maybe Hi = 0.. Hi doesnt have a value then?


For II:= 0 to Hi Do
begin
writeln('II: ' + intostr(II)); //<-- doesnt it need the Int part or Tostr?
Writeln('Hi: ' + intostr(Hi));
end;
That should print the values of II and HI everytime it loops through.. if it says 0 then you know that either II or HI was never assigned any values.. which means HI = 0 because it is looping from 0 to 0.. thats not an increase at all..

Does that make sense?? :S Kinda hard for me to explain my thoughts lol

Having a value of 0 is what it's supposed to do since the first index of the array is 0.

for i := 0 to high(arr) do // will start at arr[0] which is the first item in the array
If you go from 0 to 0, it means there's just the one index in the array (at index 0).

@Zyt3x:

[0:00:10]: [ ] ---- MSI_FindObjectsIn [27, 28, 25]
[0:00:10]: [ ] -------- No colors found!
[0:00:11]: [ ] ------ Not high enough level for object: Adamantite
[0:00:11]: 1
Error: Null Pointer Exception at line 1729
The Writeln() seems right, but still got the error on the same line.

E: Fixed it! I just moved the with..do statement outside the for loop. Not sure why it works no, but I'm glad it's fixed.

NCDS

2011-05-17 15:34:52

From: Coh3n
Having a value of 0 is what it's supposed to do since the first index of the array is 0.

for i := 0 to high(arr) do // will start at arr[0] which is the first item in the array
If you go from 0 to 0, it means there's just the one index in the array (at index 0).

@Zyt3x:

[0:00:10]: [ ] ---- MSI_FindObjectsIn [27, 28, 25]
[0:00:10]: [ ] -------- No colors found!
[0:00:11]: [ ] ------ Not high enough level for object: Adamantite
[0:00:11]: 1
Error: Null Pointer Exception at line 1729
The Writeln() seems right, but still got the error on the same line.

E: Fixed it! I just moved the with..do statement outside the for loop. Not sure why it works no, but I'm glad it's fixed.


Glad you got that figured out, I couldn't see why it was happening at all.