vandal Posted December 21, 2006 Share Posted December 21, 2006 Hello Folks and happy Festivus Season! Please be gentle i'm a newb :-) Currently I am working on a script that reads from am updating text file and mods a global variable. I want to be able to use this global as a condition on another loop. The problem is either my file read function is not changing the variable state correctly .. or my second function containing the condition isn't reading the variable state, and i haven't really been able to find an example or doc's that explain how this stuff is handled. See my Example below. Some of the reasoning behind the adlibenable is that there doesn't seem to be a clean way to get readline to read just the last line of text from the text file. I'm looking for a cleaner way of doing this .. or some clarification on how global variables can be used and manipulated by functions. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; Global $FightOver $Logfile = FileOpen("e:\logs\log.txt" , 0) DoCombat() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Check $FightOver State ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func CheckState(ByRef $FightOver) if $FightOver = 1 then Return 1 Else Return 0 EndIf EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Heartbeat state checking ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func Heartbeat() HaveGainedEXP($FightOver) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Do combat till something dies ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func DoCombat() If $Logfile = -1 Then MsgBox(0, "Error" , "Unable to open file.") Exit EndIf Do $line = FileReadLine($Logfile) until @error = -1 AdlibEnable("Heartbeat" , 300) Do Send("{1}") Sleep(3500) Send("{2}") Sleep(4000) Send("{3}") Sleep(4500) Send("{-}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{3}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{0}") Sleep(4500) Send("{3}") Sleep(4500) Send("{0}") Sleep(4500) Until CheckState($FightOver) = 1 AdlibDisable() EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;need to see if character has gained experience ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func HaveGainedEXP(ByRef $FightOver) If $Logfile = -1 Then MsgBox(0, "Error" , "Unable to open file.") Exit EndIf $line = FileReadLine($Logfile) $result = StringInStr($line , "You gain experience!") $result1 = StringInStr($line , "There is no eligible target for this spell") $result2 = StringInStr($line , "You must be engaged in combat to use this ability") $result3 = StringInStr($line , "Too little too late... Your target is already dead") $result4 = StringInStr($line , "You have killed") Select Case $result >= 1 $FightOver = 1 Case $result1 >= 1 $FightOver = 1 Case $result2 >= 1 $FightOver = 1 Case $result3 >= 1 $FightOver = 1 Case $result4 >= 1 $FightOver = 1 Case Else $FightOver = 0 EndSelect EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted December 21, 2006 Share Posted December 21, 2006 (edited) Welcome to the forums Very nice effort for your first post.... 8) Your logic is ggod, however just a little more knowledge of Autoit and you will be doing great i tried to fix-it-up some......... NOT TESTED expandcollapse popup;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; #include <File.au3> Global $FightOver, $Line, $Paused, $Logfile HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("{F9}", "DoCombat") $Logfile = FileOpen("e:\logs\log.txt", 0) If $Logfile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep(10) WEnd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Do combat till something dies ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func DoCombat() ToolTip('Now Fighting', 0, 0) AdlibEnable("HaveGainedEXP", 300) Do Send("{1}") Sleep(3500) Send("{2}") Sleep(4000) Send("{3}") Sleep(4500) Send("{-}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{3}") Sleep(4500) Send("{0}") Sleep(4500) Send("{9}") Sleep(4500) Send("{0}") Sleep(4500) Send("{3}") Sleep(4500) Send("{0}") Sleep(4500) Until $FightOver = 1 AdlibDisable() ToolTip('') EndFunc ;==>DoCombat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;need to see if character has gained experience ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func HaveGainedEXP() $Line = FileReadLine($Logfile, _FileCountLines($Logfile)) ; reads last line only If @error = -1 Then MsgBox(0, "Error", "Unable to read file.") Exit EndIf Local $Rtext = StringSplit("You gain experience!,There is no eligible target for this spell,You must be engaged in combat to use this ability" & _ "Too little too late... Your target is already dead,You have killed", ",") For $x = 1 To $Rtext[0] If StringInStr($Line, $Rtext[$x]) Then $FightOver = 1 Return 1 EndIf Next $FightOver = 0 Return 0 EndFunc ;==>HaveGainedEXP Func TogglePause() $Paused = Not $Paused While $Paused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit 0 EndFunc ;==>Terminate .... and Happy Holidays to you too! 8) Edited December 21, 2006 by Valuater Link to comment Share on other sites More sharing options...
vandal Posted December 22, 2006 Author Share Posted December 22, 2006 Thanks very much. That does clean a few things up for me. I had a look through and there's a couple of shortcuts I hadn't thought of. Could you post the code you use for _FileCountLines() please. Without that I'm still stuck on my how to read the last line of file :-) Link to comment Share on other sites More sharing options...
vandal Posted December 22, 2006 Author Share Posted December 22, 2006 Hey again. I've tried a few variations on this using some of the read last line of file function examples from the boards here. But still no real luck. The text file i'm trying to parse can end up huge, so most of the functions i've found end up being far to slow to be effective really. Anyone have a slick read only last line, or newest line of file code ideas? Also HaveGainedEXP does seem to be changing $FightOver but none of the other functions using it as a condition for something seem to pick up that change. Not sure where i'm stumbling there, looks like it should be working heh .... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now