Sign in to follow this  
Followers 0
SmOke_N

Ini - What am I doing wrong?

6 posts in this topic

#1 ·  Posted (edited)

Hey all, I started messing with .ini yesterday. And "I've fallen and I can't get up".

I have 2 windows I'm reading, and If the title changes in 1 window, I want to take an action in another.

Dim $STR

_ActionOne()

Func _ActionOne()
    
   While WinExists("My Game")
      Sleep(500)
        Local $title = WinGetTitle("My Game")
        Local $TL = StringTrimRight($title, 1)
        Local $TR = StringTrimLeft($TL, 14)
        Local $Ir1 = IniRead(@DesktopDir & "\RTB\ActionOne.ini", "Section1", "Key", "Not Found"); Used MsgBox to see if read = Yes
        Local $IW1 = IniWrite(@DesktopDir & "\RTB\ActionOne.ini", "Section1", "Key", $TR)
        
        If Not ReadIni("STR") = $Ir1 Then; Used <> also (no help)
        IniWrite(@DesktopDir & "\RTB\ActionTwo.ini", "Section1", "Key", $TR)
        FindMeNow()
        EndIf
  ; Rest of script yadda yadda yadda
    Wend
EndFunc

Func ReadIni()
    Local $STR = IniRead(@DesktopDir & "\RTB\ActionTwo.ini", "Section1", "Key", "Not Found"); Used MsgBox to see if read = Yes
    Return $STR
EndFunc

Func FindMeNow()
; Script
_ActionOne()
EndFunc

So the confusion for me begins:

For ActionOne.ini it Reads

[section1]

Key=Window Title

For ActionTwo.ini it Reads

[section1]

Key=Window Title

Here is where the actions are not being taken:

If Not ReadIni("STR") = $Ir1 Then

So, I used the MsgBox to check for errors, it returned the exact Window Title('s). Where am I going wrong?

Edit: Forgot to tell you where I was stumped!

Thanks,

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites



I am not entirely sure of the intent of the logic but I think that the problem may be that you are trying to pass a constant "STR" to a function that has no arguments defined for it.

So the solution may be to either delete the "STR" from the calling statement, viz:

If Not ReadIni() = $Ir1 Then

... or, if this is not what you intend, just add an argument to the function definition, viz:

Func ReadIni($x)

Hope this helps.


Computers don't solve problems, they just rearrange them.New string TRIM() functions for AutoIt3

Share this post


Link to post
Share on other sites

I tried your code, there was a problem with the statement:

If Not ReadIni("STR") = $Ir1 Then; Used <> also (no help)

It should be

If ReadIni() <> $Ir1 Then; Used <> also (no help)

Also, I don't see why you call 'FindMeNow()' when you detect a window change as this calls the routine that is already running. Surely this should be the routine to flag up the change.

I had to mod the code to get it to work on my pc, so here is the code I used:

Dim $STR

_ActionOne()

Func _ActionOne()

    While WinExists("UEStudio")
        Sleep(500)
        Local $title = WinGetTitle("UEStudio")
        Local $TL = StringTrimRight($title, 1)
        Local $TR = StringTrimLeft($TL, 14)
        Local $Ir1 = IniRead(@DesktopDir & "\ActionOne.ini", "Section1", "Key", "Not Found"); Used MsgBox to see if read = Yes
        Local $IW1 = IniWrite(@DesktopDir & "\ActionOne.ini", "Section1", "Key", $TR)

        If ReadIni() <> $Ir1 Then; Used <> also (no help)
            IniWrite(@DesktopDir & "\ActionTwo.ini", "Section1", "Key", $TR)
            msgbox(1,"","Window name changed")
        EndIf
    ; Rest of script yadda yadda yadda
    Wend
EndFunc

Func ReadIni()
    Local $STR = IniRead(@DesktopDir & "\ActionTwo.ini", "Section1", "Key", "Not Found"); Used MsgBox to see if read = Yes
    Return $STR
EndFunc

I don't understand why you are using the ini files though as you could store and compare the window titles as variables. I assume that you must be using them for something else.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

No I just want to know if this window has changed; and if it has, to take an action, otherwise remain to what it was doing. Would be great if you cold give an example of storing the name as a variable each time the window changed.

Till then, I'll look over what you typed.

Edit: Everytime I do it, including your example with the <>, it always reads as if they do not match. So it is constantly calling to the other function.

I checked the .ini files, and they have the same exact title.

That's where I'm confused :)

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

No I just want to know if this window has changed; and if it has, to take an action, otherwise remain to what it was doing.  Would be great if you cold give an example of storing the name as a variable each time the window changed.

Till then, I'll look over what you typed.

Edit:  Everytime I do it, including your example with the <>, it always reads as if they do not match.  So it is constantly calling to the other function.

I checked the .ini files, and they have the same exact title.

That's where I'm confused  :evil:

<{POST_SNAPBACK}>

The example I posted (as stevetowner) worked for me fine. Try taking that code as a basis.

Alternatively, try the code below using just variables. Again, it works for me! :)

_ActionOne()

Func _ActionOne()

    While WinExists("UEStudio")
        Local $PreviousWindowTitle = WinGetTitle("UEStudio")
        Sleep(500)
        Local $CurrentWindowTitle = WinGetTitle("UEStudio")

        If $PreviousWindowTitle <> $CurrentWindowTitle Then; Used <> also (no help)
            msgbox(1,"","Window name changed")
        EndIf
   ; Rest of script yadda yadda yadda
    Wend
EndFunc

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

        Local $PreviousWindowTitle = WinGetTitle("UEStudio")

        Sleep(500)

        Local $CurrentWindowTitle = WinGetTitle("UEStudio")

        If $PreviousWindowTitle <> $CurrentWindowTitle Then; Used <> also (no help)

Dope :) I can't believe I didn't ever think of that!!!

Thanks


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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