Jump to content
Sway

New to AutoIt. Help

Recommended Posts

Sway

Hi,

I need help with a script I'm creating. It will create a cool pattern that can be drawn on a graphics software my friend and I are developing.

While(1)
    Send("{down down}")
    sleep($delayDraw)
    Send("{down up}")
    sleep($delayDraw)
    Send("R down")
    sleep($delayDraw)
    Send("R up")
    sleep($delayDraw)
    Red(681,433)
    Red(681,362)
    Red(654,407)
    Red(704,406)
    Yellow(681,433)
    Yellow(681,362)
    Yellow(654,407)
    Yellow(704,406)
    Blue(681,433)
    Blue(681,362)
    Blue(654,407)
    Blue(704,406)
    ChangeDirections1(691, 593)
   WEnd

After the function "Change Directions#" doesn't return an error, I want the While Loop to end, and another While Loop to start.

While(2)
    Send("{up down}")
    sleep($delayDraw)
    Send("{up up}")
    sleep($delayDraw)
    Send("R down")
    sleep($delayDraw)
    Send("R up")
    sleep($delayDraw)
    Red(681,433)
    Red(681,362)
    Red(654,407)
    Red(704,406)
    Yellow(681,433)
    Yellow(681,362)
    Yellow(654,407)
    Yellow(704,406)
    Blue(681,433)
    Blue(681,362)
    Blue(654,407)
    Blue(704,406)
    ChangeDirections2(679,302)
   WEnd

When "Change Direction" doesn't return an error, how can I make the While Loop that the function was called in end and another While Loop to start?

 

For example, let's call the specific loops "While 1" and "While 2" 

After the function "Change Directions1" in "While 1" doesn't return an error, I want "While 1" to end and "While 2" to start. 

When the function "Change Directions2" in "While 2" doesn't return an error, I want "While 2" to end and "While 1" to start again.

 

Is there any command to start a line of code inside of a function? For example, look at line 4. Line 1 would represent the start of "While 1" and Line 20 would represent "While 2"

Func ChangeDirections1($x, $y)
    $detect = PixelSearch($x - 5, $y - 5, $x + 5, $y + 5, 0x97968A,5)
        if not(@error) Then
            "command that runs code at Line 1 and below"
EndFunc

Func ChangeDirections2($x, $y)
    $detect = PixelSearch($x - 5, $y - 5, $x + 5, $y + 5, 0x808080,5)
        if not(@error) Then
            "command that runs code at Line 20 and below"
EndFunc

 

Edited by Sway

Share this post


Link to post
Share on other sites
careca

Instead of 2 loops, i'd have 1 and alternate the code with a variable and a condition.

$loop = 1

If 1 run first part

else run the second


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Sway
8 hours ago, careca said:

Instead of 2 loops, i'd have 1 and alternate the code with a variable and a condition.

$loop = 1

If 1 run first part

else run the second

can you show me how? I'm kind of new to this haha

Share this post


Link to post
Share on other sites
careca

one way to do it

#include <Misc.au3>
$Action = 1
While 1
If _IsPressed(21) Then ;page up
    $Action = 1
ElseIf _IsPressed(22) Then ;page down
    $Action = 2
EndIf
If $Action=1 Then
    ConsoleWrite('Action 1 - '&@MSEC&@CRLF)
ElseIf $Action = 2 Then
    ConsoleWrite('Action 2 - '&@MSEC&@CRLF)
EndIf
WEnd

 

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Sway

would I replace the ConsoleWrite lines with my code, and what is the _IsPressed part? thanks so much!

22 minutes ago, careca said:

one way to do it

#include <Misc.au3>
$Action = 1
While 1
If _IsPressed(21) Then ;page up
    $Action = 1
ElseIf _IsPressed(22) Then ;page down
    $Action = 2
EndIf
If $Action=1 Then
    ConsoleWrite('Action 1 - '&@MSEC&@CRLF)
ElseIf $Action = 2 Then
    ConsoleWrite('Action 2 - '&@MSEC&@CRLF)
EndIf
WEnd

 

 

Edited by Sway

Share this post


Link to post
Share on other sites
Earthshine

open the help file and start reading.


My resources are limited. You must ask the right questions

 

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

×