Sign in to follow this  
Followers 0
Mumms

Help

5 posts in this topic

#1 ·  Posted (edited)

There are no errors when I Syntex Check, and I can compile this and run it. But Then I get an error saying that a variable has be used without being declared. . Logicly This should work, as far as I can tell ;) and it shouldn't be giving me this error. Any help with fixing this? Thanks.

Edited by Mumms

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You're trying to use $checkDup on line 19 before dclaring it.

Yes you are automatically declaring it by assigning a value to it on line 17, but then it won't be used. And because the automatic declaration is local and only lasts untill the function returns, it will not be declared the next time the function runs.

You should also consider the following to improve the script a bit.

$dup += 1 ;increase $dup by 1 (See operators in the helpfile)
Return ;returns from a function before reaching the end. (skipping any further code in the function)
Local ;Use this to explicitly declare all variables you wish to destry once a function ends, or for all variables that will only be used outside any function.
Global ;Use this to explicitly declare all remaining variables at the start of the script. OUTSIDE any functions!
; <= this is all you need to do to not do anything. Calling a function that does not do anything is a bit like going to the supermarket to buy nothing, instead of just not going to the supermarket. (see Return to end a function early.)
If $dupCheck <> 0 Then ; opposite of If $dupCheck = 0 Then, so it's true if dupCheck is not 0
If Not ($dupCheck = 0) Then ;Same as above, Usually it's better to us <>.

As a last note I'd like to say that seeing some code is usefull, having the full functional script and all files it needs to reproduce the error is better, but ideally you'd write a reproducer, which will often give you your answer before posting anything.

Edit:

P.s: If you post the whole script I'd be willing to have a look and make suggestions where needed.

Edited by Tvern

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the fast response.

Edited by Mumms

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Right. To fix that error you can probably just declare $checkDup as global, but there is a whole bunc of other issues with the script. I'll see if I can sort of fix them, but I still can't run it without the needed file, so It's going to be guesswork.

Edit: I had to guess what some parts should do and I'm not sure if this will run for you. But atleast the basis is a bit cleaner now. I'm gonna be away for the rest of the day, but I'll check back tomorrow if you have any follow up issues.

#include<Array.au3>
#include <Date.au3>
#include <File.au3>


#RequireAdmin


Global $sVersion = "1.2"
Global $iPlayersPlayed = 0

;***********Makes sure path is correct for future file reading***************
If FileExists("SoF2MP-Test.exe") Then
    If MsgBox(1, "A Trime Design: ATD", "SoF2 Personal Stats [SPS]" & @CRLF & " " & @CRLF & "www.team-vip.t83.net" & @CRLF & " " & @CRLF & "Version: " & $sVersion) = 2 Then
    Exit
    EndIf
Else
    MsgBox(16, "Error", "Place Me In Your Main Sof2 Directory" & @CRLF & " Please Contact Trime if the problem continues")
    Exit
EndIf

Global $hFile = FileOpen("demo/MP/qconsole.log",1)
If $hFile = -1 Then
    MsgBox(0,"Error","File could not be opened for reading")
    Exit
EndIf
OnAutoItExitRegister("_Exit") ;to make sure the file is closed properly

While 1
;~  FileGetTime() not sure what you want this to do.
    If FileExists("demo/MP/qconsole.log") Then readLog()
    Sleep(500)
Wend

;***********Reads Last Line of the log file***********

 Func readLog()
    Local $sLine, $sName, $iCount
    $sLine = FileReadLine($hFile) ;Assuming you want to start at the first line and then continue from there?
    $sName = StringRegExpReplace($sLine,"\^7 was shot by (.*).+\^7","$1",1) ;I think you needed to escape the first ^. Try to optimize this to only return the player name.
    $iCount = @extended ;is there a maximum of one shot per line? (if there is then this could be simplified.
    If @error Or ($iCount = 0) Then Return
    IniWrite("Kills.ini", "Kills", $sName, IniRead("Kills.ini", "Kills", $sName,0)+$iCount) ;increase shotcount by the amount of shots found for the found player.
EndFunc

;This is not a completed Function yet, Just counts players in file and returns it. (will do this anyway)

Func players()
    Local $aSections = IniReadSectionNames("Kills.ini") ;need some errorchecking here
    For $i = 1 To $aSections[0]
    $iPlayersPlayed += 1 ;this is just going to end up as the value already in $aSections[0]
    Next
EndFunc

Func _Exit()
    FileClose($hFile)
EndFunc
Edited by Tvern

Share this post


Link to post
Share on other sites

Automatic declaration is ******** [censored]!

I never understand, why Opt("MustDeclareVars", 1) isn't set by DEFAULT! Every serious programmer is pec-declaring variables. Beginners could save much time wasted by debugging if they are forced to pre-declare variables.

(just my opinion)

A-Jay


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

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