Results 1 to 15 of 15

Thread: [RESOLVED] Error: Null Pointer Exception

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default [RESOLVED] Error: Null Pointer Exception

    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:
    Progress Report:
    [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:
    Simba Code:
    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:
    Simba Code:
    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

  2. #2
    Join Date
    Sep 2010
    Location
    Finland
    Posts
    299
    Mentioned
    8 Post(s)
    Quoted
    37 Post(s)

    Default

    UpTexts[I] := MSI_Objects[Objs[I]].UpText;
    TheOptions[I] := MSI_Objects[Objs[I]].Option;
    There's one square bracket too much on Obsj[I]], atleast I think that's the problem.
    It should be [II].

  3. #3
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Smidqe View Post
    There's one square bracket too much on Obsj[I]], atleast I think that's the problem.
    It should be [II].
    Sorry nope.

    What exactly is MSI_Objects?
    Last edited by HyperSecret; 05-17-2011 at 02:01 PM.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  4. #4
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Smidqe View Post
    There's one square bracket too much on Obsj[I]], 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.

  5. #5
    Join Date
    Sep 2010
    Location
    Finland
    Posts
    299
    Mentioned
    8 Post(s)
    Quoted
    37 Post(s)

    Default

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

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default For II := 0 To Hi Do With MSI_Objects[Objs[II]] Do

    :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:

    Code:
    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])]
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    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.
    Last edited by Coh3n; 05-17-2011 at 02:19 PM.

  8. #8
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

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

  9. #9
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Simba has borked line numbers, you can't really trust those..
    I made a new script, check it out!.

  10. #10
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    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).

  11. #11
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Try doing
    Simba Code:
    For II := 0 To Hi Do
    begin
      WriteLn(ToStr(II));
      with MSI_Objects...
    instead of
    Simba Code:
    For II := 0 To Hi Do
      with MSI_Objects...
    and see what II is right before the error occurs.
    Interesting..
    Simba Code:
    [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.
    Last edited by Coh3n; 05-17-2011 at 03:31 PM.

  12. #12
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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?

    Code:
    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
    Last edited by Brandon; 05-17-2011 at 03:57 PM.
    I am Ggzz..
    Hackintosher

  13. #13
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Interesting..
    Simba Code:
    [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

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

  14. #14
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by ggzz View Post
    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?

    Code:
    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.
    Simba Code:
    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:
    Progress Report:
    [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.
    Last edited by Coh3n; 05-17-2011 at 05:12 PM.

  15. #15
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Having a value of 0 is what it's supposed to do since the first index of the array is 0.
    Simba Code:
    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:
    Progress Report:
    [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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •