Sign in to follow this  
Followers 0
OMNIslash3D

Issues with the FileOpen Command.

5 posts in this topic

#1 ·  Posted (edited)

I made a script, and an hour or an hour and a half into it, the script has been locking up on me, and just kind of freezing, but I still have access to my pause and exit hot keys, so I'm quite dumbfounded to whats been going on. Last night I set up a few console comments around the script that would let me know where the script was somehow getting locked up in. The last comment in the console that I have seen the last few times I've run the script points to line 100, meaning it has to be getting stuck in between line 100 and the next console comment. However, since I put the console comments in, I've been getting a little error box that comes up and says "Error allocating memory." Can anyone kind of help me figure out what's going wrong here? Here is the code from line 100 to the next console comment:

ConsoleWrite(@ScriptLineNumber & ' ')
    
Sleep(Random(1000, 1500))
PathFollow("startToGate.txt")

Basically, the next ConsoleWrite function that will write another comment to the console of scite is in the PathFollow function which I have created. It's fairly simple. Basically what it does is it reads a .txt file line by line. The .txt file has a 0, 1, or 2 on each line that another program recorded based on what buttons I had pressed down at a specific time. Basically this PathFollow function re-enacts what buttons I had pressed down in the same time frame that I had originally put them in. The 2 functions together, essentially record a set of actions over a given time frame, and then in the same amount of time, the PathFollow will read those actions that I was doing, and then put them out in the same order and time that I was doing them. Here is the PathFollow function:

Func PathFollow($a)
    $end = 0
    $file = 0
    $go = 0
    Do
        $file = FileOpen($a, 0)
        If $file = -1 Then
        Else
            $go = 1
        EndIf
    Until $go = 1
    $go = 0
    
    $delay = FileReadLine($file,1)
    $prevVert = 0
    $prevHori = 0
    $count = 1
    ConsoleWrite(@ScriptLineNumber & ' ')
    Do
        Sleep($delay)
        $vert = FileReadLine($file)
        $hori = FileReadLine($file)
        
;$count += 2
        
        If $vert = 1 And ($prevVert = 0 Or $prevVert = 2) Then
            Send("{d up}")
            Send("{e down}")
            $prevVert = $vert
        EndIf
        
        If $vert = 2 And ($prevVert = 0 Or $prevVert = 1) Then
            Send("{e up}")
            Send("{d down}")
            $prevVert = $vert
        EndIf
        
        If $vert = 0 And ($prevVert = 1 Or $prevVert = 2) Then
            Send("{e up}")
            Send("{d up}")
            $prevVert = $vert
        EndIf
        
        If $hori = 1 And ($prevHori = 0 Or $prevHori = 2) Then
            Send("{f up}")
            Send("{s down}")
            $prevHori = $hori
        EndIf
        
        If $hori = 2 And ($prevHori = 0 Or $prevHori = 1) Then
            Send("{s up}")
            Send("{f down}")
            $prevHori = $hori
        EndIf
        
        If $hori = 0 And ($prevHori = 1 Or $prevHori = 2) Then
            Send("{s up}")
            Send("{f up}")
            $prevHori = $hori
        EndIf
        
        If $vert == "end"  Then
            $end = 1
            Send("{e up}")
            Send("{d up}")
            Send("{s up}")
            Send("{f up}")
        EndIf
    Until $end = 1
    
    ConsoleWrite(@ScriptLineNumber & ' ')
    Do
        $go = FileClose($file)
        Sleep(Random(150,250))
        ConsoleWrite(@ScriptLineNumber & ' ')
    Until $go = 1
    ConsoleWrite(@ScriptLineNumber & ' ')
EndFunc;==>PathFollow

Now somewhere in here there is a memory leak or something, and its having a memory allocating error, and it is never getting to the next "ConsoleWrite(@ScriptLineNumber & ' ')". I recently added the loops around the fileopen and file close statements to make sure the file opens and closes itself, thinking that, this might solve the issue I was originally having, and I think that might be causing the memory allocating error, although I don't understand why. is there any reason my program would be freezing in this particular instance? Any help is appreciated. Thanks in advance!

EDIT: I thought there might be some confusion about this. The program that creates the .txt file inserts "end" when the file is done recording so that when the pathfollow function reads it, it knows when to end.

Edited by OMNIslash3D

Share this post


Link to post
Share on other sites



Some suggestions

* Remove all send commands / block them out and look if the program runs thru till the end

* Check on End Of File (@Error=-1) instead of end text

* Add two lines with "end" to txt file to check if it comes to the end

* Add a counter in the loop and let the counter write to the console (consolewrite) so you can see on what line in textfile things are breaking

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Some suggestions

* Remove all send commands / block them out and look if the program runs thru till the end

* Check on End Of File (@Error=-1) instead of end text

* Add two lines with "end" to txt file to check if it comes to the end

* Add a counter in the loop and let the counter write to the console (consolewrite) so you can see on what line in textfile things are breaking

took your suggestions. This is the new PathFollow() function I made :

Func PathFollow($a)
    $end = 0
    $file = 0
    $go = 0
    $file = 0
    $vert = 0
    $hori = 0

    $file = FileOpen($a, 0)

    
    
    $delay = FileReadLine($file, 1)
    $prevVert = 0
    $prevHori = 0
    $count = 1
    CheckDC()
    $fileLineCount = 0
    ConsoleWrite(@ScriptLineNumber & ' ')
    Do
        $fileLineCount += 1
        Sleep($delay)
        $vert = FileReadLine($file)
        $hori = FileReadLine($file)
        If @error = -1 Then
            $end = 1
            Send("{e up}")
            Send("{d up}")
            Send("{s up}")
            Send("{f up}")
        EndIf
        $count += 1
        If $count > 50 Then
            $return = CheckDC()
            If $return = 1 Then
                $return = 0
                return 1
            EndIf
            $count = 0
        EndIf
        
        If $vert = 1 And ($prevVert = 0 Or $prevVert = 2) Then
            Send("{d up}")
            Send("{e down}")
            $prevVert = $vert
        EndIf
        
        If $vert = 2 And ($prevVert = 0 Or $prevVert = 1) Then
            Send("{e up}")
            Send("{d down}")
            $prevVert = $vert
        EndIf
        
        If $vert = 0 And ($prevVert = 1 Or $prevVert = 2) Then
            Send("{e up}")
            Send("{d up}")
            $prevVert = $vert
        EndIf
        
        If $hori = 1 And ($prevHori = 0 Or $prevHori = 2) Then
            Send("{f up}")
            Send("{s down}")
            $prevHori = $hori
        EndIf
        
        If $hori = 2 And ($prevHori = 0 Or $prevHori = 1) Then
            Send("{s up}")
            Send("{f down}")
            $prevHori = $hori
        EndIf
        
        If $hori = 0 And ($prevHori = 1 Or $prevHori = 2) Then
            Send("{s up}")
            Send("{f up}")
            $prevHori = $hori
        EndIf
    Until $end = 1
    
    CheckDC()
    ConsoleWrite(@ScriptLineNumber & ' ')

    $go = FileClose($file)

EndFunc ;==>PathFollow

I declared $fileLineCount as a global variable at the top of the script, and incremented it through the entire file. I added access to the variable through the pause function I have:

Func TogglePause()
    MsgBox(0,$fileLineCount, $fileLineCount)
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc ;==>TogglePause

and then I woke up this morning and took a look at the $fileLineCount variable, and it is currently at 1287956, (the text files are not anywhere close to this long) meaning that something is going wrong with this function. In my first post when I put loops around the opening of the file to make sure the file opened, but I was getting memory errors:

Do
        $file = FileOpen($a, 0)
        If $file = -1 Then
        Else
            $go = 1
        EndIf
    Until $go = 1

It's my guess that this was the source of the problem of the memory error. It works initially, but after about an hour and a half, it just stops working. It currently does not have the above loop in it, but the $file = FileOpen($a, 0) is still there, and for some reason it seems to be failing in the act of opening the file. Is there a reason for this perhaps? Is the file not closed properly? Initally, the first time the program loops through its entire long sequence, everything works fine. It will work for a second, third, fourth, maybe fifth time, but eventually this happens and it fails. Any advice? I'm really kind of stumped...

Edited by OMNIslash3D

Share this post


Link to post
Share on other sites

First check if your file is properly opened.

Is the file accessed by another program at the same time?

Is the file in the right directory? Try with full directory names?

$file = FileOpen($a, 0)

; Check if file opened for reading OK
If $file = -1 Then
    consolewrite(0, "Error", "Unable to open file." & $a)
    Exit
EndIf

You could try a sleep after closing the file of 1-2 seconds. To make sure OS gets time to clean up?

Share this post


Link to post
Share on other sites

First check if your file is properly opened.

Is the file accessed by another program at the same time?

Is the file in the right directory? Try with full directory names?

$file = FileOpen($a, 0)

; Check if file opened for reading OK
If $file = -1 Then
    consolewrite(0, "Error", "Unable to open file." & $a)
    Exit
EndIf

You could try a sleep after closing the file of 1-2 seconds. To make sure OS gets time to clean up?

Tried all of your suggestions, still no luck. It consistently happens about an hour and a half to 2 hours into the programs running. Never the first time, so I feel its the application somehow backing itself up. I created another program that actually executes this program, and I took out the giant loop, so every time it loops I just have it boot up the program all over again. I shouldn't really have to do that, but there isn't much else I can do. Why is this happening? I don't understand :-(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0