Results 1 to 10 of 10

Thread: Access Violation Error

  1. #1
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default Access Violation Error

    This keeps throwing an access violation error at the writeln.


    I am trying to read the text "mid flash", "mid tp", "top flash" *examples*
    start a timer to keep track of when these will be back up to use and delete those lines so it does
    not reset the timer.

    Simba Code:
    procedure OpenTest;     //Reads text!!!
    var
      i,z: Integer;
      hFile: Integer;
      pSize: Integer;
      pString: String;
      pStringArray : TStringArray;
      pUserInfo: TStringArray;
    begin
      hFile := OpenFile('C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.204\MyNotes.txt', false);
      if ((hFile <> -1) and ReadFileString(hFile, pString, FileSize(hFile))) then
      begin
        pStringArray := Explode(#10, pString);

        for i := 0 to high(pStringArray) do
        begin
          pUserInfo := Explode(' ', pStringArray[i]);
          repeat
            writeln('' ,pUserInfo[i], ' ' ,pUserInfo[i+1]);
         // TStringArray.deleteIndex(i);
          //TStringArray.deleteIndex(i+1);
         until
          EndOfFile(hFile);
        end;
      end;
     CloseFile(hFile);
    end;
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    You're using the same variable i for two different arrays: pStringArray and pUserInfo.

  3. #3
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default

    I see!
    How would I get it to print several lines without having to repeat the for to do loop?


    **Edit**

    I changed the I to a Z and it works now!
    Simba Code:
    procedure OpenTest;     //Reads text!!!
    var
      i, z, p, u, y: Integer;
      hFile: Integer;
      pSize: Integer;
      pString: String;
      pStringArray : TStringArray;
      pUserInfo: TStringArray;
    begin
      hFile := OpenFile('C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.204\MyNotes.txt', false);
      if ((hFile <> -1) and ReadFileString(hFile, pString, FileSize(hFile))) then
      begin
        pStringArray := Explode(#10, pString);

        for i := 0 to high(pStringArray) do
        begin
          pUserInfo := Explode(' ', pStringArray[i]);
          //repeat
            writeln('' ,pUserInfo[z], '' ,pUserInfo[z+1]);
            //writeln('' ,pUserInfo[z], '' ,pUserInfo[z+1]);
         // TStringArray.deleteIndex(0);
          //TStringArray.deleteIndex(1);
         //until


      end;
     CloseFile(hFile);
    end;
    end;
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  4. #4
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    You do realize that z is just zero in the case, right? I'm guessing that you're expecting pUserInfo to have a length of 2. If so, then you're better off doing something like this:
    Simba Code:
    if (Length(pUserInfo) = 2) then WriteLn(pUserInfo[0], ' ', pUserInfo[1]);

  5. #5
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default

    I did not realize that but I did know that it does start from 0.
    I need to obviously look at some tuts or arrays.

    Simba Code:
    mf := 'mid flash';

     if (Length(pUserInfo) = 2) then
            WriteLn(pUserInfo[0], ' ', pUserInfo[1]);
            pUserInfo.toString('mid flash'); //Trying to use TStringArray.toString, says too many parameters
          if containsMatch(mf, 'mid flash') then
            writeln('Found mid flash');
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  6. #6
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Yeah, no offense but you seem very confused by this
    It looks like you're using SRL-6? The toString function doesn't take any parameters. It just 'implodes' an array into a single string.
    Could you post an example of what this whole text file might look like?

  7. #7
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default

    Idea would be to read each line, start a timer, remove those lines from the text file and then read the text file again to see if anything new
    has been added to make a new timer.

    Haha no offense taken I haven't done much programing and I started to read some tuts but just tried to jump head first into this.
    I do appreciate your help so far.


    Code:
    mid flash
    top flash
    bot heal
    mid ignite
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  8. #8
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Here is what I could throw together for now. I'll have more time to mess with it after work.
    Simba Code:
    1. program TextTest;
    2.  
    3. type
    4.   TSkillTImer = Record
    5.     Text: String;
    6.     Timer: UInt32;
    7.   end;
    8.  
    9.   TSkillTimerArray = Array of TSkillTimer;
    10.  
    11. const //idk the actual values
    12.   FLASH_TIME  = 300000;
    13.   HEAL_TIME   = 300000;
    14.   IGNITE_TIME = 300000;
    15.  
    16. var
    17.   Timers: TSkillTimerArray;
    18.  
    19. function MsToTime(MS: UInt32): string;
    20. var
    21.   STA: array [0..5] of TVariantArray;
    22.   Time: array of Integer;
    23.   i, t, tl: Integer;
    24. begin
    25.   Result := '';
    26.  
    27.   tl := 3;
    28.   t := 2;
    29.   SetLength(Time,tl);
    30.   ConvertTime(MS, Time[0], Time[1], Time[2]);
    31.  
    32.   STA[3] := [':', ':', '', True, 2];
    33.  
    34.   for i := 0 to t do
    35.     if (Time[i] > 0) or (STA[3][tl]) or (i = t) then
    36.       Result := Result + PadZ(IntToStr(Time[i]), STA[3][tl+1]) + STA[3][i];
    37. end;
    38.  
    39. procedure LoadTimers();
    40. var
    41.   i: Int32;
    42.   T: TSkillTimer;
    43.   S: String;
    44.   List: TStringList;
    45. begin
    46.   List.Init();
    47.   try
    48.     List.LoadFromFile(AppPath + 'test.txt');
    49.     CloseFile(RewriteFile(AppPath + 'test.txt', True));
    50.     if (List.GetCount() < 1) then Exit;
    51.     for i := 0 to (List.GetCount() - 1) do
    52.     begin
    53.       S := List.GetStrings(i);
    54.       if (Pos('flash', LowerCase(S)) > 0) then
    55.       begin
    56.         T.Text := S;
    57.         T.Timer := GetTickCount() + FLASH_TIME;
    58.         Timers := Timers + T;
    59.       end else
    60.       if (Pos('heal', LowerCase(S)) > 0) then
    61.       begin
    62.         T.Text := S;
    63.         T.Timer := GetTickCount() + HEAL_TIME;
    64.         Timers := Timers + T;
    65.       end else
    66.       if (Pos('ignite', LowerCase(S)) > 0) then
    67.       begin
    68.         T.Text := S;
    69.         T.Timer := GetTickCount() + IGNITE_TIME;
    70.         Timers := Timers + T;
    71.       end;
    72.     end;
    73.   finally
    74.     List.Free();
    75.   end;
    76. end;
    77.  
    78. procedure ReadTimers();
    79. var
    80.   i: Int32;
    81.   t: UInt32 := GetTickCount();
    82.   Temp: TSkillTimerArray;
    83. begin
    84.   if (Length(Timers) < 1) then Exit;
    85.   ClearDebug();
    86.   for i := 0 to High(Timers) do
    87.   begin
    88.     if (t < Timers[i].Timer) then
    89.     begin
    90.       Temp := Temp + Timers[i];
    91.       WriteLn(Timers[i].Text, ' ', MsToTime(Timers[i].Timer - t));
    92.     end;
    93.   end;
    94.   Timers := Temp;
    95. end;
    96.  
    97. procedure Loop();
    98. begin
    99.   LoadTimers();
    100.   ReadTimers();
    101.   Wait(900);
    102. end;
    103.  
    104. begin
    105.   ClearDebug();
    106.   while True do Loop();
    107. end.

  9. #9
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Here is what I could throw together for now. I'll have more time to mess with it after work.
    Simba Code:
    1. program TextTest;
    2.  
    3. type
    4.   TSkillTImer = Record
    5.     Text: String;
    6.     Timer: UInt32;
    7.   end;
    8.  
    9.   TSkillTimerArray = Array of TSkillTimer;
    10.  
    11. const //idk the actual values
    12.   FLASH_TIME  = 300000;
    13.   HEAL_TIME   = 300000;
    14.   IGNITE_TIME = 300000;
    15.  
    16. var
    17.   Timers: TSkillTimerArray;
    18.  
    19. function MsToTime(MS: UInt32): string;
    20. var
    21.   STA: array [0..5] of TVariantArray;
    22.   Time: array of Integer;
    23.   i, t, tl: Integer;
    24. begin
    25.   Result := '';
    26.  
    27.   tl := 3;
    28.   t := 2;
    29.   SetLength(Time,tl);
    30.   ConvertTime(MS, Time[0], Time[1], Time[2]);
    31.  
    32.   STA[3] := [':', ':', '', True, 2];
    33.  
    34.   for i := 0 to t do
    35.     if (Time[i] > 0) or (STA[3][tl]) or (i = t) then
    36.       Result := Result + PadZ(IntToStr(Time[i]), STA[3][tl+1]) + STA[3][i];
    37. end;
    38.  
    39. procedure LoadTimers();
    40. var
    41.   i: Int32;
    42.   T: TSkillTimer;
    43.   S: String;
    44.   List: TStringList;
    45. begin
    46.   List.Init();
    47.   try
    48.     List.LoadFromFile(AppPath + 'test.txt');
    49.     CloseFile(RewriteFile(AppPath + 'test.txt', True));
    50.     if (List.GetCount() < 1) then Exit;
    51.     for i := 0 to (List.GetCount() - 1) do
    52.     begin
    53.       S := List.GetStrings(i);
    54.       if (Pos('flash', LowerCase(S)) > 0) then
    55.       begin
    56.         T.Text := S;
    57.         T.Timer := GetTickCount() + FLASH_TIME;
    58.         Timers := Timers + T;
    59.       end else
    60.       if (Pos('heal', LowerCase(S)) > 0) then
    61.       begin
    62.         T.Text := S;
    63.         T.Timer := GetTickCount() + HEAL_TIME;
    64.         Timers := Timers + T;
    65.       end else
    66.       if (Pos('ignite', LowerCase(S)) > 0) then
    67.       begin
    68.         T.Text := S;
    69.         T.Timer := GetTickCount() + IGNITE_TIME;
    70.         Timers := Timers + T;
    71.       end;
    72.     end;
    73.   finally
    74.     List.Free();
    75.   end;
    76. end;
    77.  
    78. procedure ReadTimers();
    79. var
    80.   i: Int32;
    81.   t: UInt32 := GetTickCount();
    82.   Temp: TSkillTimerArray;
    83. begin
    84.   if (Length(Timers) < 1) then Exit;
    85.   ClearDebug();
    86.   for i := 0 to High(Timers) do
    87.   begin
    88.     if (t < Timers[i].Timer) then
    89.     begin
    90.       Temp := Temp + Timers[i];
    91.       WriteLn(Timers[i].Text, ' ', MsToTime(Timers[i].Timer - t));
    92.     end;
    93.   end;
    94.   Timers := Temp;
    95. end;
    96.  
    97. procedure Loop();
    98. begin
    99.   LoadTimers();
    100.   ReadTimers();
    101.   Wait(900);
    102. end;
    103.  
    104. begin
    105.   ClearDebug();
    106.   while True do Loop();
    107. end.
    Holy.....that is way more than I was thinking it would take...when you have time do you mind explaining some of that to me?
    I really appreciate you writing that. I am gonna look through it and try to figure out what all is going on.

    *Edit*
    It seems to work flawless! It keeps the current time going even if a new line is added.
    I am blown away man.
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  10. #10
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by Element17 View Post
    Holy.....that is way more than I was thinking it would take...when you have time do you mind explaining some of that to me?
    I really appreciate you writing that. I am gonna look through it and try to figure out what all is going on.
    Sure, no problem. I think the easiest way is to message me on Discord, but you can PM me here or just reply to this thread if that works better.
    SRL Discord: https://discord.gg/bgN9srT
    You can message me from there, or just Citrus#0408

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
  •