Sign in to follow this  
Followers 0
xXCABLEDOGXx

Several Questions

8 posts in this topic

Not like you don't already get questions all the time like, "Sorry I'm new, can you help me..." But, Sorry, I'm new, can you help me?

I understood and have worked with a few commands already, and have had a lot of success in my scripting, but I do have a few questions that will hopefully streamline my scripting. Please bear with me that I haven't "tried" my own questions to see if they work, I haven't had a lot of time to play with AutoIt yet, and don't want to "waste" time if it doesn't or won't work.

So, without further delay, here are my questions:

1. Can Screen Coordinates and Colors be assigned to a $String?

IE: While PixelGetColor ($CoordA) <> $PixelA

a. If this can be done, I've seen example scripts that call for these variables in .INI files. How do I include an .INI file into my .au3?

2. Can Functions be defined within an .INI file, or must they reside within the actual script?

Basically what I am hoping to be able to do is modify my script without having to run line by line in the code, just jump to the appropriate variable or function and modify from there if needed.

Thanks for any assistance :unsure:

xXCABLEDOGXx

Share this post


Link to post
Share on other sites



xXCABLEDOGXx,

Welcome to the AutoIt forum. :unsure:

1. Can Screen Coordinates and Colors be assigned to a $String?

Anything beginning with a $ is a variable - which can be a number, a string, a Boolean, a pointer, a handle...... AutoIt is dynamically typed - it tries to do its best to use the right type but you sometimes have to set the type specifically, which si why we have the Number, String, Ptr, etc functions.

You can definitely put a coordinate into a variable.

How do I include an .INI file into my .au3?

You do not. You just define the particular file you want use in the "filename" parameter of the Ini* function:

IniRead ( "filename", "section", "key", "default" )

And, of course, this string value could be stored in a variable. ;)

Can Functions be defined within an .INI file, or must they reside within the actual script?

You cannot define functions within an ini file - what you need is an include file. This is a standard .au3 file which you add using the #include directive - this adds the code of the include file at the point the directive appears in your script.

Does that help? Please ask again if not. :>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

So, With the INI file, I will be setting variables, and then "loading" those variables into the script when called for, and as for functions, I will create a separate .au3 file to encompass any and all functions that I want to use, and then call on them as needed?

xXCABLEDOGXx,

Welcome to the AutoIt forum. :unsure:

Anything beginning with a $ is a variable - which can be a number, a string, a Boolean, a pointer, a handle...... AutoIt is dynamically typed - it tries to do its best to use the right type but you sometimes have to set the type specifically, which si why we have the Number, String, Ptr, etc functions.

You can definitely put a coordinate into a variable.

You do not. You just define the particular file you want use in the "filename" parameter of the Ini* function:

IniRead ( "filename", "section", "key", "default" )

And, of course, this string value could be stored in a variable. ;)

You cannot define functions within an ini file - what you need is an include file. This is a standard .au3 file which you add using the #include directive - this adds the code of the include file at the point the directive appears in your script.

Does that help? Please ask again if not. :>

M23

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Your functions dont have to be in a separate file, they just can be, its very useful for large projects or keeping your functions organised etc...

In the following code, your function is fine where it is, or if you uncomment the include directive at the top, it will happily work in its own

file named "MyFuncs.au3"

;#include "MyFuncs.au3"

$s_inifile = "myinifile.ini"

$s_MyNumber = IniRead($s_inifile,"NUMBERS","mynumber","0")

$i_MyNumber = Number($s_MyNumber)

$i_MyNumberTimesTen = _MultiplyMyNumber($i_MyNumber)

MsgBox(0,"Result",$i_MyNumberTimesTen)

Func _MultiplyMyNumber($i_Value)
    $i_Result = $i_Value * 10
    Return $i_Result
EndFunc

myinifile.ini

[NUMBERS]
mynumber = 7
If you change the number in your infile, the output will change. Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you guys for all your help. I have just a few more questions, if I may, then perhaps I will be sated (*grin*)

I find myself wanting to create a "toggle" switch in my looping statements. I guess the best way is to give a brief example of it. Something a long these lines (and forgive me, I know the code I am about to write doesn't work, but I am unsure how to proceed)

The basis is simple, while a variable like $Toggle = 0, I want my loops that check for certain functions to not work, and by sending a command that gets parsed by the script which if = "toggle on" then $Toggle = 1. While $Toggle is equal to 1, perform set checks and run said functions.

$Toggle = 0

While 1=1

While $Toggle = 0

CheckForToggleOn()

CheckForToggleOff()

OnlyPerformThis()

OnlyPerformThat()

WEnd

While $Toggle = 1

CheckForToggleOn()

CheckForToggleOff()

PerformThisAndThat()

AsWellAsThatAndThis()

WEnd

WEnd

Func CheckForToggleOn()

If $LastLineOfLog = "Toggle On" Then

$Toggle = 1

Else

$Toggle = 0

EndIf

EndFunc

Func CheckForToggleOff()

If $LastLineOfLog = "Toggle Off" Then

$Toggle = 0

Else

$Toggle = 1

EndIf

EndFunc

As you can see, I am setting up an "infinite" loop, one that will close when I choose to close it, but also, one that will only perform some or no checks while $Toggle = 0, and perform all @ $Toggle = 1.

However, I have met limited success, and have had to remove this feature from my script altogether. I've tried variations that did not work, and I was wondering if I might be looking at this from the wrong perspective.

Again, any help is greatly appreciated, and thanks in advance.

*EDIT*

Oh yeah, and I attempted to place screen coordinates in a variable, unfortunately this did not work , the script responded with something along the lines of "This arguement can only have one somethingoranother" when it saw a line like this: $CheckCoord = 222, 32 ... Would this have to be defined as an Array variable? Or is it just less headaches to have a $CheckCoordX / $CheckCoordY and have them in the PixelGetColor () statement? That's what I am doing now, and it works very well, was just wondering if X and Y could be defined in a single variable (string)

Thanks in advance again :unsure:

xXCableDogXx

Your functions dont have to be in a separate file, they just can be, its very useful for large projects or keeping your functions organised etc...

In the following code, your function is fine where it is, or if you uncomment the include directive at the top, it will happily work in its own

file named "MyFuncs.au3"

;#include "MyFuncs.au3"

$s_inifile = "myinifile.ini"

$s_MyNumber = IniRead($s_inifile,"NUMBERS","mynumber","0")

$i_MyNumber = Number($s_MyNumber)

$i_MyNumberTimesTen = _MultiplyMyNumber($i_MyNumber)

MsgBox(0,"Result",$i_MyNumberTimesTen)

Func _MultiplyMyNumber($i_Value)
    $i_Result = $i_Value * 10
    Return $i_Result
EndFunc

myinifile.ini

[NUMBERS]
mynumber = 7
If you change the number in your infile, the output will change.

Edited by xXCABLEDOGXx

Share this post


Link to post
Share on other sites

xXCABLEDOGXx,

Here is a pretty simple template which should help you: ;)

#include <GUIConstantsEx.au3>

$fToggle = False

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton("Toggle", 10, 10, 80, 30)

$hLabel = GUICtrlCreateLabel("Off", 10, 100, 100, 20)

GUISetState()

While 1

    ; Check the toggle
    If $fToggle = True Then
        OnlyPerformThis()
    Else
        PerformThisAndThat()
    EndIf

    ; Check if anything has happened
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; If button was pressed, toggle the toggle
            $fToggle = Not $fToggle
            Switch $fToggle
                ; Set label accordingly
                Case True
                    GUICtrlSetData($hLabel, "On")
                Case False
                    GUICtrlSetData($hLabel, "Off")
            EndSwitch
    EndSwitch

WEnd

Func OnlyPerformThis()
    ConsoleWrite("Only Performing This" & @CRLF)
EndFunc

Func PerformThisAndThat()
    ConsoleWrite("Performing This And That" & @CRLF)
EndFunc

There are more complicated ways to break into the functions, but let us see if this is good enough for you at the moment. :D

Please ask if anything is unclear. :unsure:

M23

trancexx look away now! :)

P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. ;)

P.P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code. :>


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba, that was great information. And useful, though I stripped out the GUI, but fully functional, I didn't see the SELECT/CASE functions before, I must have missed those.

As usual, since starting this thread :unsure: I have another question...

I want to be able to move the mouse pointer within a rectangular area (the size doesn't really matter, just between coordinate points on the screen), and click on the screen every so often.

I've done this using coordinates that I mapped out, but it is an ungangly, unsexy looking little script that requires about 40 lines of code. I started to experiment with something a little more streamlined (which I will post in code) so you can see what I am talking about, maybe you can point me in the right direction... or tell me it can't be done (I will accept either answer lol). Thanks in advance again for any assistance :>

For $i = 375 To 292 Step 10
        For $j = 742 to 559 Step 10
            MouseMove($i, $j, 0)
            MouseDown ("left")
            MouseUp   ("left")
        Next
    Next

What I am trying to accomplish with that little snippet is to make the mouse pointer scan within the bounds of those parameters and click down. Obviously, this example doesn't work. In fact, nothing happens at all. And even further, if I apply an endless loop like While 1=1 /WEnd, the script exits on it's own with no error message. *SIGH* This time, before posting, I went through all of my functions that I *believed* pertained to what I was trying to do, and I have come up with nothing so far.

Signed, Frustrated ;)

Thanks.

Share this post


Link to post
Share on other sites

xXCABLEDOGXx,

- 1. You are coding your For...Next loops with the first parameter larger then the second - in that case you need to use a negative Step value (or reverse the values). ;)

- 2. MouseClick did not jump out at you? :>

Try this: :D

For $i = 375 To 292 Step -10
    For $j = 742 to 559 Step -10
        MouseClick("left", $i, $j)
    Next
Next

I thought I had become inured to the strange things people want to do with AutoIt, but this is pretty bizarre! :unsure: Why on earth do you want to click like this?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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