Answered by:
What am I doing wrong?

Question
-
Hello there,
I created a little script the should read out a raster of blocks out of the game Bejeweled 3.
The language is written in a Basic-like language (for Autoit)
The only issue is: When reading out Pixelcolors it gives me an error on my created Function.
Can you guys tell me what I am doing wrong?
Func _readPixels() _log("Start reading pixels") $pixelShift = _getNextPixelShiftSet() $shiftHorizontal = $pixelShift[1] $shiftVertical = $pixelShift[2] ToolTip('Reading pixels playfield', 0, 0) dim $Field[8][8] $k=0 $l=0 for $j = $field1[1] to $field3[1] step $blockWidth for $i = $field1[0] to $field2[0] step $blockWidth $field[$k][$l] = pixelgetColor($i + $shiftHorizontal,$j + $shiftVertical) ;mousemove($i + $shiftHorizontal,$j + $shiftVertical,40) ;Sleep(500) $k = $k + 1 next $l = $l + 1 $k = 0 next return $field EndFunc
The complete script till now is:;-------------------- DECLARATION SECTION -------------------- #include <array.au3> #include <file.au3> Global $paused ;sets up pause hotkey HotKeySet("{ESC}", "_quit") ;set escape hotkey to exit HotKeySet("{PAUSE}", "_pause") ;set pasue hotkey to pause _log("Initializing bejeweled bot...") $iniFile=stringleft(@ScriptName,stringlen(@scriptname)-4) & ".ini" if not FileExists($iniFile) Then msgbox(0,"","The ini file could not be found at following location: " & $iniFile) exit EndIf $windowBejeweled3=IniRead ( $iniFile, "Common" , "windowBejeweled3", "" ) $cornerColor1=IniRead ( $iniFile, "Common" , "cornerColor1", "0x9A6043" ) $cornerColor4=IniRead ( $iniFile, "Common" , "cornerColor4", "0x040404" ) $corner1 = _ArrayCreate("","") $corner2 = _ArrayCreate("","") $corner3 = _ArrayCreate("","") $corner4 = _ArrayCreate("","") $Field1 = _ArrayCreate("","") $Field2 = _ArrayCreate("","") $Field3 = _ArrayCreate("","") $BlockWidth = 0 $AmountGems=IniRead ( $iniFile, "Common" , "AmountGems", 0 ) ;Calculate distance between center of each gem $BlockWidth = ($Corner2[0] - $Corner1[0]) / $AmountGems $Field1[0]=$Corner1[0] + ($BlockWidth / 2) $Field1[1]=$Corner1[1] + ($BlockWidth / 2) $Field2[0]=$Corner2[0] - ($BlockWidth / 2) $Field2[1]=$Corner1[1] + ($BlockWidth / 2) $Field3[0]=$Corner3[0] + ($BlockWidth / 2) $Field3[1]=$Corner3[1] - ($BlockWidth / 2) $pixelShift=IniRead ( $iniFile, "Common" , "pixelShift", 0 ) $searchDelay=IniRead ( $iniFile, "Common" , "searchDelay", 1200 ) ;-------------------- MAIN SECTION --------------------------- if winactivate($windowBejeweled3)= 0 then msgbox(0,"","Window " & $windowBejeweled3 & " could not be found.") exit endif _log("Searching top left Color of playfield") ToolTip('Searching top left Color pixel with Color ' & hex($cornerColor1, 6) , 0, 0) $Corner1 = pixelSearch(0,0,@DesktopWidth,@DesktopHeight, $cornerColor1,0) If @error Then msgbox(0,"","Top Left pixel with Color: " & hex($cornerColor1, 6) & " not found") exit Else MouseMove($corner1[0],$corner1[1]) endif _log("Searching bottom right Color of playfield") ToolTip('Searching bottom right Color pixel with Color ' & hex($CornerColor4, 6) , 0, 0) $Corner4=_pixelSearchReverse(0,0,@DesktopWidth,@DesktopHeight, $CornerColor4) If @error Then msgbox(0,"","Bottom Right pixel with Color: " & hex($CornerColor4, 6) & " not found") exit Else MouseMove($corner4[0],$corner4[1]) endif ;Calculate Color of remaining corners $Corner2[0]=$Corner4[0] $Corner2[1]=$Corner1[1] $Corner3[0]=$Corner1[0] $Corner3[1]=$Corner4[1] ;Read pixel shift sets into an array Global $pixelShiftSetCounter = 0 Global $pixelShiftSet = StringSplit($PixelShift,"/") ;For each pixel shift set, create an array storing the x and y coordinates for $i = 1 to Ubound($pixelShiftSet) - 1 $pixelShiftSet[$i] = stringSplit($pixelShiftSet[$i],",") Next while 1 $switched = false $field = _ReadPixels() _LogPixels() ToolTip('Start checking if gems can be moved', 0, 0) ;PLACEHOLDER for the movement of gems ToolTip('Stop checking if gems can be moved', 0, 0) if $switched = true then sleep($searchDelay) _log("a move was performed") Else _log("checked whole field, no moves were done") endif _log("") wend ;-------------------- FUNCTION SECTION ----------------------- ;makes a quit function Func _quit() Exit EndFunc ;makes a pause function Func _pause() $paused = Not $paused While $paused Sleep(100) ToolTip('Script is "Paused, to unpause press pause key"', 0, 0) WEnd ToolTip("") EndFunc Func _Log($message) _FileWriteLog(@scriptDir & "\output.txt", $message) EndFunc Func _pixelSearchReverse($left,$top,$right,$bottom,$Color) $coordFoundColor=_ArrayCreate("-1","-1") $i = 0 $j = 0 for $i = @DesktopWidth to 0 Step -1 for $j = @DesktopHeight to 0 Step -1 $currentColor = PixelGetColor($i,$j) if $currentColor = $Color then $coordFoundColor[0] = $i $coordFoundColor[1] = $j return $coordFoundColor endif next next SetError(-1) endFunc Func _ArrayCreate($v_0, $v_1 = 0, $v_2 = 0, $v_3 = 0, $v_4 = 0, $v_5 = 0, $v_6 = 0, $v_7 = 0, $v_8 = 0, $v_9 = 0, $v_10 = 0, $v_11 = 0, $v_12 = 0, $v_13 = 0, $v_14 = 0, $v_15 = 0, $v_16 = 0, $v_17 = 0, $v_18 = 0, $v_19 = 0, $v_20 = 0) Local $av_Array[21] = [$v_0, $v_1, $v_2, $v_3, $v_4, $v_5, $v_6, $v_7, $v_8, $v_9, $v_10, $v_11, $v_12, $v_13, $v_14, $v_15, $v_16, $v_17, $v_18, $v_19, $v_20] ReDim $av_Array[@NumParams] Return $av_Array EndFunc ;==>_ArrayCreate Func _getNextPixelShiftSet() if $PixelShiftSetcounter < (Ubound($PixelShiftSet) - 1) then $PixelShiftSetcounter = $PixelShiftSetcounter + 1 else $PixelShiftSetcounter = 1 endif _log("Using Pixelshiftset with number " & $PixelShiftSetcounter & " and content " & _ArrayToString($PixelShiftSet[$PixelShiftSetcounter],",",1)) return $PixelShiftSet[$PixelShiftSetcounter] EndFunc Func _readPixels() _log("Start reading pixels") $pixelShift = _getNextPixelShiftSet() $shiftHorizontal = $pixelShift[1] $shiftVertical = $pixelShift[2] ToolTip('Reading pixels playfield', 0, 0) dim $Field[8][8] $k=0 $l=0 for $j = $field1[1] to $field3[1] step $blockWidth for $i = $field1[0] to $field2[0] step $blockWidth $field[$k][$l] = pixelgetColor($i + $shiftHorizontal,$j + $shiftVertical) ;mousemove($i + $shiftHorizontal,$j + $shiftVertical,40) ;Sleep(500) $k = $k + 1 next $l = $l + 1 $k = 0 next return $field EndFunc Func _logpixels() $i = 0 $j = 0 for $j = 0 to 7 $line = "" for $i = 0 to 7 $temp = $field[$i][$j] $line = $line & " " & hex($temp) next _Log($line) next _Log("") EndFunc
Sunday, October 5, 2014 12:12 PM
Answers
-
As I have no experience with AutoIt (because this forum is about the Small Basic language) I cannot exactly pinpoint your error. But the errormessage said that the subscript dimension is out of range, I suspect that $k or $l becomes bigger than 7 during the running of the program. You can insert a statement to display the values of $k and $l just before the offending statement. If one of them becomes bigger than 7, you should look at the cacculation of thes variables.
Jan [ WhTurner ] The Netherlands
- Proposed as answer by Nonki Takahashi Tuesday, October 7, 2014 3:27 AM
- Marked as answer by litdev Wednesday, October 15, 2014 7:09 PM
Sunday, October 5, 2014 4:20 PMAnswerer -
You should look at one of the following links to get help for AutoIt:
- Proposed as answer by Nonki Takahashi Tuesday, October 7, 2014 3:27 AM
- Marked as answer by litdev Wednesday, October 15, 2014 7:09 PM
Sunday, October 5, 2014 6:56 PMAnswerer
All replies
-
BTW, the error is:
Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
It gives me this error on the following line:$field[$k][$l] = pixelgetColor($i + $shiftHorizontal,$j + $shiftVertical)
Sunday, October 5, 2014 12:15 PM -
As I have no experience with AutoIt (because this forum is about the Small Basic language) I cannot exactly pinpoint your error. But the errormessage said that the subscript dimension is out of range, I suspect that $k or $l becomes bigger than 7 during the running of the program. You can insert a statement to display the values of $k and $l just before the offending statement. If one of them becomes bigger than 7, you should look at the cacculation of thes variables.
Jan [ WhTurner ] The Netherlands
- Proposed as answer by Nonki Takahashi Tuesday, October 7, 2014 3:27 AM
- Marked as answer by litdev Wednesday, October 15, 2014 7:09 PM
Sunday, October 5, 2014 4:20 PMAnswerer -
You should look at one of the following links to get help for AutoIt:
- Proposed as answer by Nonki Takahashi Tuesday, October 7, 2014 3:27 AM
- Marked as answer by litdev Wednesday, October 15, 2014 7:09 PM
Sunday, October 5, 2014 6:56 PMAnswerer