Sign in to follow this  
Followers 0
Phat Phil

Dumb Questions

5 posts in this topic

I'd like to know more about array's & functions.

How do you make a function, how do you call on it to do the function.

Also say I want a boolegan, and if the boolegan is false I want it to go back up the script to say line 200 when the boolegan was at 300. How would I do this?

What are arrays, what are they used for and how do I use them?

Dumb questions I know but I've never had to get very in depth with these parts of the code.

Global $Paused

HotKeySet("{END}", "TogglePause")

HotKeySet("{HOME}", "Terminate")

While 1

Sleep(100)

WEnd

Func TogglePause()

$Paused = NOT $Paused

While $Paused

WEnd

EndFunc

Func Terminate()

Exit 0

EndFunc

I've always used the code above as a skeleton which I took from a d2 script. Then I would put the code between While $Paused and WEnd. Try'd putting functions between it and I dont think your allowed.. However I do like the thing where I can hit End key and start the script and terminate it with the Home key. Should I not be using the above code to start ne thing?

Share this post


Link to post
Share on other sites



I'd like to know more about array's & functions.

How do you make a function, how do you call on it to do the function.

Also say I want a boolegan, and if the boolegan is false I want it to go back up the script to say line 200 when the boolegan was at 300. How would I do this?

What are arrays, what are they used for and how do I use them?

Dumb questions I know but I've never had to get very in depth with these parts of the code.

Global $Paused

HotKeySet("{END}", "TogglePause")

HotKeySet("{HOME}", "Terminate")

While 1

Sleep(100)

WEnd

Func TogglePause()

$Paused = NOT $Paused

While $Paused

WEnd

EndFunc

Func Terminate()

Exit 0

EndFunc

I've always used the code above as a skeleton which I took from a d2 script. Then I would put the code between While $Paused and WEnd. Try'd putting functions between it and I dont think your allowed.. However I do like the thing where I can hit End key and start the script and terminate it with the Home key. Should I not be using the above code to start ne thing?

You make a function by using the code

func functionname

;code here

endfunc

To call this in your code you would just use

functionname

As to going to line numbers - if you write your code in functions you could use the function names instead of line numbers.

Arrays - are variables grouped together - example would be a map where you have ABC and 123 along different edges and each letter and number combo gives a different location on the map - in a varaible array - $array[1][2] will have a different value than $array[1][1]

As for its uses - group similar variables into the same name - you could even create a record with different values for each index.

Hope this helps, but if not the help file explains arrays as well as the forum has lots of examples.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Also, using that code as a skeleton isn't a bad thing, and you are allowed to add more functions in it. Where you place the function in a script does not matter as long as it begins with "Func fuctionname" and ends with "EndFunc" then you can call it from anywhere in the script. You can assign any key with HotKeySet() function, so you don't always have to use Home and End keys. I don't really like the idea of setting a variable ($Paused) to make the hotkey react differently, I think just reassigning the hotkey is less confusing (but either way works fine). Here is another way you could achieve the same thing (aside from the fact that I made the End key end the program which seems to make more sense to me):

HotKeySet("{HOME}", "DoWhatever") ;Set HOME key to start the main function
HotKeySet("{END}", "Terminate") ;Set END key to exit the program

PauseScript() ;Call PauseScript function which will make the script sleep

Func DoWhatever()
     HotKeySet("{HOME}", "PauseScript") ;reassign the HOME key to pause the script
     While 1 ;The number 1 just tells it to go forever (or until it's interrupted but a hotkey being pressed)

          ;Put your code here
          
     WEnd
EndFunc

Func PauseScript()
     HotKeySet("{HOME}", "DoWhatever") ;reassign the HOME key to start the main function again
     While 1
          Sleep(100) ;Just makes script sleep until it's given further instruction (a hotkey is pressed)
     WEnd
EndFunc

Func Terminate()
     Exit
EndFunc

EDIT: Also as Niketram has mentioned, all of the functions are documented in the help file including: Function name, Function parameters, Return values, Related functions, and even an example of the function in use. It's a very "helpful" resource :whistle:.

Edited by dandymcgee

- Dan [Website]

Share this post


Link to post
Share on other sites

Is there a way to make AutoIt do something to a window that is minimized?

Like say I normally write a code to tell it to move mouse to 123,400 and clicks.

Can I tell autoit to do that without actually having the window up. That way as the script runs I can do other things on the comp.

Share this post


Link to post
Share on other sites

Look up the ControlClick() function as I don't believe the window has to be active to receive input from this function (although it obviously still has to exist). Even with this function, it's not a very good idea (depending on what you are automating) to try to use the computer for other things while a script that sends key presses and clicks is being executed as... some unexpected results may occur :whistle:.


- Dan [Website]

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