Jump to content

A little syntax error help


kart442
 Share

Recommended Posts

Just can't seem to get this to work...

Thanks for your help.

#include <Array.au3>
For $board_x = 1 To 8
    For $board_y = 1 To 8
        $size_x = 63
        $size_y = 63
        $start_x = 677
        $start_y = 686
        $x_coord = (($board_x * $size_x) + $start_x) <= 1118
        $y_coord = ($start_y - ($board_y * $size_y)) >= 245
        Dim $pixel[$x_coord][$y_coord]
        For $x = 0 To ($x_coord)
            For $y = 0 To ($y_coord)
                $pixel[$x][$y] = (PixelGetColor($x, $y))
            Next
        Next
    Next
Next
Link to comment
Share on other sites

#include <Array.au3>
For $board_x = 1 To 8
    For $board_y = 1 To 8
        $size_x = 63
        $size_y = 63
        $start_x = 677
        $start_y = 686
        $x_coord = (($board_x * $size_x) + $start_x) <= 1118
        $y_coord = ($start_y - ($board_y * $size_y)) >= 245
        Dim $pixel[$x_coord + 1][$y_coord + 1]
        For $x = 0 To ($x_coord)
            For $y = 0 To ($y_coord)
                $pixel[$x][$y] = (PixelGetColor($x, $y))
            Next
        Next
    Next
Next

Link to comment
Share on other sites

#include <Array.au3>
For $board_x = 1 To 8
    For $board_y = 1 To 8
        $size_x = 63
        $size_y = 63
        $start_x = 677
        $start_y = 686
        $x_coord = (($board_x * $size_x) + $start_x) <= 1118
        $y_coord = ($start_y - ($board_y * $size_y)) >= 245
        Dim $pixe[color=[$x_coord + 1][$y_coord + 1]
        For $x = 0 To ($x_coord)
            For $y = 0 To ($y_coord)
                $pixel[$x][$y] = (PixelGetColor($x, $y))
            Next
        Next
    Next
Next
Thanks, Didn't know you could put [+1] there, but I have another problem it only returns [2][2] and not [8][8] (need all 64 squares) any suggestions? Edited by kart442
Link to comment
Share on other sites

Would it not be something to do with this line?

$x_coord = (($board_x * $size_x) + $start_x) <= 1118
        $y_coord = ($start_y - ($board_y * $size_y)) >= 245

I'm unsure if you can do 2 expressions there? <_< (The expression on the end)

Edited by Bert
Link to comment
Share on other sites

Would it not be something to do with this line?

$x_coord = (($board_x * $size_x) + $start_x) <= 1118
        $y_coord = ($start_y - ($board_y * $size_y)) >= 245

I'm unsure if you can do 2 expressions there? <_< (The expression on the end)

It did change but it came back with [740][250]!!!! :)
Link to comment
Share on other sites

Link to comment
Share on other sites

  • Developers

what are these statements supposed to do ?

your current version will return 1 or 0 (boolean) since you are comparing ...

<_<

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Maybe I going about this all wrong?

I would like to read the pieces of a chess board (all at the same time) so I can use that info to make a move.

677 is my starting x coord

686 is my starting y coord

each square is 63x63 pixels

8 rows

8 cols

Link to comment
Share on other sites

You shouldn't be using the pixel functions at all. You should have an 8x8 array representing every position on the board with a unique identifier for each piece. Ever since you posted the first topic about chess I began working on a checkers game, look at this beta code:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.8.1
 Author:         WeaponX

 Script Function:
    Checkers
    
 Script Version:
    Pre-Alpha

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

Dim $boardRows = 8, $boardCols = 8

Dim $boardArray[$boardRows][$boardCols]

Dim $boardWidth = 400, $boardHeight = 400

Dim $boardColor1 = 0x333333, $boardColor2 = 0xcccccc

Dim $pieceColor1 = 0xcc0000, $pieceColor2 = 0x6699cc

GUICreate("Checkers", $boardWidth, $boardHeight)

$boardGraphic = GUICtrlCreateGraphic (0,0, $boardWidth, $boardHeight)
;GUICtrlSetBkColor(-1,0x000000)
;GUICtrlSetGraphic(-1,$GUI_GR_COLOR, "",0xfe0002)

$flipColor = false
For $X = 0 To 7
    For $Y = 0 to 7
        If $flipColor Then
            ;Draw square color1
            GUICtrlSetGraphic($boardGraphic,$GUI_GR_COLOR, $boardColor1,$boardColor1)

            
            $flipColor = false
        Else
            ;Draw square color2
            GUICtrlSetGraphic($boardGraphic,$GUI_GR_COLOR, $boardColor2,$boardColor2)
            
            $flipColor = true
        EndIf
        GUICtrlSetGraphic($boardGraphic,$GUI_GR_RECT, $Y * ($boardWidth / $boardCols),$X * ($boardHeight / $boardRows), $boardWidth / $boardCols,$boardHeight / $boardRows)
    Next
    If $flipColor Then
        $flipColor = false
    Else
        $flipColor = true
    EndIf
Next

;Must be after all GUICtrlCreateGraphic unless refresh option is used
GUISetState (@SW_SHOW)

redraw()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Func redraw()

    ;Draw set 1
    $flipColor = false
    For $X = 0 To 2
        For $Y = 0 to 7
            If $flipColor Then
                ;Draw piece
                ;GUICtrlSetColor (-1, $pieceColor2)
                $flipColor = false
            Else        
                ;Draw piece                
                GUICtrlCreateLabel ( "l", $Y * ($boardWidth / $boardRows),$X * ($boardHeight / $boardCols), $boardWidth / $boardCols,$boardHeight / $boardRows, $SS_CENTER )
                GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
                GUICtrlSetFont(-1, 34, "", "", "Wingdings")    
                GUICtrlSetColor (-1, $pieceColor1)
                $flipColor = true
            EndIf
        Next
        If $flipColor Then
            $flipColor = false
        Else
            $flipColor = true
        EndIf
    Next
    
    ;Draw set 2
    $flipColor = false
    For $X = 5 To 7
        For $Y = 0 to 7            
            If $flipColor Then
                ;Draw piece
                GUICtrlCreateLabel ( "l", $Y * ($boardWidth / $boardRows),$X * ($boardHeight / $boardCols), $boardWidth / $boardCols,$boardHeight / $boardRows, $SS_CENTER )
                GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
                GUICtrlSetFont(-1, 34, "", "", "Wingdings")                    
                GUICtrlSetColor (-1, $pieceColor2)
                $flipColor = false
            Else        
                ;Draw piece
                ;GUICtrlSetColor (-1, $pieceColor1)
                $flipColor = true
            EndIf
        Next
        If $flipColor Then
            $flipColor = false
        Else
            $flipColor = true
        EndIf
    Next
EndFunc
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...