Jump to content

A few questions


Nez
 Share

Recommended Posts

I'd like to preface this by saying I've searched through some threads and used the search function, but have failed to find anything to help me with some confusion. I apologize in advance if I have somehow missed something blatantly obvious. I'm new to scripting, and so far have been successful at utilizing the help file within the autoit directory, however I have a few questions that I feel may be obvious but I am not understanding.

I am making a basic script to emulate key presses "Send("d"), you get the point. Seeing as the goto function no longer exists, I am running into a cluttering problem -- my script is super messy. I am wondering if someone could explain to me briefly how to create a function that is its own file that I can call.. Like this:

;Example messy script

If $var = 1 then

Send("D")

Send("P")

Send("T")

Send("X")

Else

Send("O")

Send("I")

Can I take those functions, make it a file, like dptx.au3 (named after the keys pressed,) and use the file as a function? So it would instead look like this:

; Example of cleaner script

#include <dptx.au3>

#include <oi.au3>

If $var = 1 then

use <function named dptx.au3>

Else

use <function named oi.au3>

Am I even going about it the right way?

Link to comment
Share on other sites

Is Func ... EndFunc what you are looking for? Look for 'User Define Functions' in the help file.

Example:

$Var=1
If $Var=1 Then
    _SayHello()
Else
    _SayBye()
EndIf

;here are the user defined functions:
Func _SayHello()
    MsgBox(0,"","hello")
EndFunc

Func _SayBye()
    MsgBox(0,"","Bye")
EndFunc
Link to comment
Share on other sites

I see. Yeah I think that will work. So instead my "cleaner" code would look like this?

; User Defined Functions

Func _dptx()
     Send("D")
     Send("P")
     Send("T")
     Send("X")
EndFunc

Func _oi()
    Send("O")
    Send("I")
EndFunc

; Start code    
If $var = 1, Then
    _dptx()
Else
    _oi()
EndIf

Okay, that makes sense. Is there a reason you put the user defined functions at the bottom? Thank you for your input!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...