Jump to content
Sign in to follow this  

Question about the forum

Recommended Posts

I know it says not to discuss game automation here and that is not what I want to do.

However I do want to post an example of something I wrote earlier which was designed for that purpose (I do it for fun because I'm a gamer and like to test my abilities with autoit)

Anyway the question is...

Is it ok to post code without telling you what it is for when the code could easily be used for anything and ask about improving the way I'm writing code in general.

The code in question has no window titles or anything that would possibly lead you to what it was written for.

If I can't post this kind of code here is there a place I can post it in order to be critiqued?

Thanks (If this is ok to post I will edit and add it)

Share this post

Link to post
Share on other sites

Don't you think posting code without any information about what its purpose is or what it should do is just silly.

Now if you like to get feedback on your coding style/skills I suggest you just pick some code where you can give some information about its purpose. (or find a alternative purpose for the code in question.)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...

Share this post

Link to post
Share on other sites

Yeah it's kind of a gray area I know...

I don't see how posting something without giving the exact purpose would be silly.

For instance this code simply waits on 1/4 pixels to change then it goes into a wait period.

When those pixels have stopped changing for a set amount of time it logs the last pixel ID (1-4).

It then adds that to the array and then plays it back from start to finish.

But yeah If I can't post it simply for that reason it kind of stinks because this is how I challenge myself to write more...

There are a few things in particular I'm curious about with auto it.

For instance I don't know how large my array will be it could potentially be infinite.

So why should I have to declare

Local $array[255]

Such a large amount.

I'm sure there's a way to modify array size on the fly... Most scripting languages I'm familiar with you can use functions such as arrayadd("blah blah blah") and it just automatically creates a new index and fills it in.

I could be wrong though

Share this post

Link to post
Share on other sites

So I would assume this means I need to make sure I ReDim the array before it gets full or it will crash right...

Or is there a way to do it as it would crash?

Thank you for the very helpful suggestion

#include <Array.au3>

AutoItSetOption( "MouseClickDelay", 150)
AutoItSetOption( "MouseClickDownDelay", 150)

HotKeySet("{F9}", "quit");hotkey to quit

Local $colorson[5]
Local $colorsonx[5]
Local $colorsony[5]
Local $recorded[255]

$colorson[0] = 16764108
$colorson[1] = 13434828
$colorson[2] = 13421823
$colorson[3] = 16777215

$colorsonx[0] = 763
$colorsony[0] = 603

$colorsonx[1] = 920
$colorsony[1] = 597

$colorsonx[2] = 764
$colorsony[2] = 727

$colorsonx[3] = 913
$colorsony[3] = 730

$wait1 = 50

$mode = 1
$waittime = 0
$length = 0

While 1=1
    $mouse = MouseGetPos()
    $colorsfound = 0
    if $mode = 1 Then
        $tooltip = "Stuff... " & $length & " - " & $waittime
        For $i = 0 To 4
            $pix = PixelGetColor( $colorsonx[$i], $colorsony[$i])
            if $pix = $colorson[$i] Then
                $tooltip = "A COLOR IS ON"
                $colorsfound = $colorsfound + 1
                $colorfound = $i
                $waittime = 0
                if $length = 0 Then
                    $recorded[$length] = $colorfound
                    $length = $length + 1
        if $colorsfound = 0 Then
            $waittime = $waittime + 1
            if $waittime > 16 Then
                if $length > 0 Then
                    $recorded[$length] = $colorfound
                    $length = $length+1
                    $mode = 3
    If $mode = 3 Then
        $pos = 1
        While $pos < $length
            $tooltip = "Playback... " & $pos
            $rnd = random( -15, 15, 1)
            MouseClick( "LEFT", $colorsonx[$recorded[$pos]]+$rnd, $colorsony[$recorded[$pos]]+$rnd, 1, 5)
            $rnd = random(5, 35)
            $pos = $pos + 1
        $rnd = random( -25, 25)
            MouseMove( 834+$rnd, 655+$rnd, 0)
        $waittime = 0
        $mode = 1
    tooltip( $tooltip, 508+50, 458+25)

func quit()
  MsgBox(0, "Goodbye", "You really messed it up this time!")

There's the code in question with all comments removed.

Basically it's just a simple pixel search of 4 very specific coordinates... it waits for a change... logs last change by waiting for changes to stop... adds that change to the array...

then plays back the coords in the order they changed then repeats the entire process.

I do apologize for comment removal and lack of cleaning up now obsolete portions.

Edited by LordNeo

Share this post

Link to post
Share on other sites

Like so:

Global $STACK_MAX = 1 ;maximum size of the search stack
Global $STACK[$STACK_MAX] ;the search stack
$STACK[0] = 0 ;stack element counter
Func _Push($var) ;Utility function. DO NOT CALL
    If $STACK[0] > $STACK_MAX - 2 Then
        $STACK_MAX *= 2
        ReDim $STACK[$STACK_MAX]
    $STACK[0] += 1
    $STACK[$STACK[0]] = $var
    Return 1
EndFunc   ;==>_Push
Func _Pop() ;Utility function. DO NOT CALL
    If $STACK[0] > 0 Then
        $STACK[0] -= 1
        Return $STACK[$STACK[0] + 1]
    Return 0
EndFunc   ;==>_Pop
Edited by omikron48

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...