Sign in to follow this  
Followers 0
JohnOne

Changing a variable

12 posts in this topic

I'm trying to change a found variable to a new value, but getting headaches.

Using tessedract to read the screen but its returning a Z as XY.

If I use iniread and tell it to read the XY value in it and then tell it to change it to Z then it works fine returning $1 in the msgbox as Z

But using teseract Which returns XY, it's still returned in msgbox as XY

#include <Tesseract.au3>
$coord0 = PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44)
Sleep(1000)
$1 = _TesseractScreenCapture(0,"",1,1,$coord0[0] + 283,$coord0[1] + 133,$coord0[0] + 298,$coord0[1] + 151,0)
If $1 = "XY" Then 
   $1 = "Z"
EndIf
MsgBox(0, "New Value = ", $1)

Is there something blatently obvious I'm missing

I've tried incorperating ByRef into the tesseractscreencapture, but get syntax errors

Any ideas very welcome


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



I've never used Tesseract.au3 but a quick look shows that_TesseractScreenCapture documentation says that it returns an array nota string.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Cheers for the heads up

I've altered the code

#include <Tesseract.au3>
local $1[1]
$coord0[0] = PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44)
Sleep(1000)
$1[0] = _TesseractScreenCapture(0,"",1,1,$coord0[0] + 283,$coord0[1] + 133,$coord0[0] + 298,$coord0[1] + 151,0)
If $1[0] = "XY" Then 
   $1[0] = String("Z")
EndIf
MsgBox(0, "New Value = ", $1[0])

Still no joy, same result

Any other pointers appreciiated


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Cheers for the heads up

I've altered the code

#include <Tesseract.au3>
local $1[1]
$coord0[0] = PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44)
Sleep(1000)
$1[0] = _TesseractScreenCapture(0,"",1,1,$coord0[0] + 283,$coord0[1] + 133,$coord0[0] + 298,$coord0[1] + 151,0)
If $1[0] = "XY" Then 
   $1[0] = String("Z")
EndIf
MsgBox(0, "New Value = ", $1[0])

Still no joy, same result

Any other pointers appreciiated

Well, that's not how you declare and use an array.

But it doesn't matter because if you look at the code for _TesseractScreenCapture(), a string is returned UNLESS you provide a delimiter in the second parameter -- then it would string split on that delimiter and return the array. That's not what the function header says, but that's what the code does.

:D

P.S. The accuracy isn't very good on my test. I ran this code:

#include <Tesseract.au3>

Global $Coord, $Capture
WinActivate("Untitled - Notepad")
$Coord = WinGetPos("Untitled - Notepad")
Sleep(1000)
$Capture = _TesseractScreenCapture(0, "", 1, 1, $Coord[0] + 10,$Coord[1] + 50, $Coord[0] + 200, $Coord[1] + 200, 0)
If IsArray($Capture) Then
    _ArrayDisplay($Capture, "$Capture")
Else
    ConsoleWrite("String $Capture = " & $Capture)
EndIf

The open Notepad window contained this:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
This is line 8
This is line 9

And this is the string I got back:

String $Capture = This is 'lina 1
This is Tina 2
This is Tins Z
This is Tina 4
This is 'Iina 5
This is `lina 6
This is Tina 7
This is Tins S
{This is Tins 9

:D

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well after running that script I have (rightly or wrongly) came to the conclusion that tesseractscreencapture is not returning an array.

My figuring is : if it were an array, then _ArrayDisplay($Capture, "$Capture") would be called into play, which it is not.

I also tried this code with my problem

#include <Tesseract.au3>
$coord0 = String(PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44))
Sleep(1000)
$1 = _TesseractScreenCapture(0,"",1,1,$coord0[0] + 283,$coord0[1] + 133,$coord0[0] + 298,$coord0[1] + 151,0)
If $1 = "XY" Then 
   $1 = "Z"
EndIf
MsgBox(0, "New Value = ", $1)

Without any success

I've tried a number of ways which I thought it could possibly be, some brought errors and others just gave the same result of XY in msgbox :D

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Well after running that script I have (rightly or wrongly) came to the conclusion that tesseractscreencapture is not returning an array.

My figuring is : if it were an array, then _ArrayDisplay($Capture, "$Capture") would be called into play, which it is not.

I also tried this code with my problem

#include <Tesseract.au3>
$coord0 = String(PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44))
Sleep(1000)
$1 = _TesseractScreenCapture(0,"",1,1,$coord0[0] + 283,$coord0[1] + 133,$coord0[0] + 298,$coord0[1] + 151,0)
If $1 = "XY" Then 
   $1 = "Z"
EndIf
MsgBox(0, "New Value = ", $1)

Without any success

I've tried a number of ways which I thought it could possibly be, some brought errors and others just gave the same result of XY in msgbox :D

Regardless of how Tesseract.au3 works, your use of arrays gets farther out to sea with every attempt. Some review of the help file and the wiki tutorial on arrays would help you a lot. In this case String() destroys the array returned by PixelSearch().

Try simplifying the script to individual steps and check the outputs at each step.

1. Are you getting a valid array back from PixelSearch()? How do you know?

2. What is the string you get back from the tesseract function? (BEFORE you manipulate it any way!)

3. etc.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#include <SimpleTesseract.au3>
Sleep(2000)
$coord0 = PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44)

MsgBox(0, "", $coord0[0] & $coord0[1]) ;this is displaying both the x and y coords of the specified pixel colour

$1 = _TesseractScreenCapture(0, "", 1, 1, $coord0[0] + 282, $coord0[1] + 133, $coord0[0] + 297, $coord0[1] + 150, 0)

MsgBox(0, "$1 = ", $1) ; this is displaying XY
MsgBox(0, "$1 = ", $1[0]) ; this errors "Subscript used with non-Array variable.:"

If $1 = "XY" Then
    $1 = "Z"
EndIf

MsgBox(0, "$1 now = ", $1) ; this is displaying XY

I cannot see what I am doing wrong

Im thinking the non-arry error is because its not an array, just a simple variable

I'm totally stumped as to why it wont change


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#include <SimpleTesseract.au3>
Sleep(2000)
$coord0 = PixelSearch(0, 0, @DesktopWidth / 2, @DesktopHeight / 2, 0x346C44)

MsgBox(0, "", $coord0[0] & $coord0[1]) ;this is displaying both the x and y coords of the specified pixel colour

$1 = _TesseractScreenCapture(0, "", 1, 1, $coord0[0] + 282, $coord0[1] + 133, $coord0[0] + 297, $coord0[1] + 150, 0)

MsgBox(0, "$1 = ", $1) ; this is displaying XY
MsgBox(0, "$1 = ", $1[0]) ; this errors "Subscript used with non-Array variable.:"

If $1 = "XY" Then
    $1 = "Z"
EndIf

MsgBox(0, "$1 now = ", $1) ; this is displaying XY

I cannot see what I am doing wrong

Im thinking the non-arry error is because its not an array, just a simple variable

I'm totally stumped as to why it wont change

Okay, what did you want to change?

In AutoIt, when you set the value of a variable, it assumes that type. So, regardless of what type it was before, $coord0 becomes an array IF the return value of PixelSearch() is an array. (It's possible PixelSearch() might not return an array if there's an error.)

The function _TesseractScreenCapture() can return either a string or an array. Because you did not give it a delimitter (second parameter = "") it will return a string. So, regardless of what type it was before, $1 becomes a string. Because it is a string, any array index syntax, like $1[0] will cause an error. Adding the index value "[0]" to a string variable will not change it into an array, only produce the error.

In situations where you don't know if a variable is going to be an array or not, always test it with IsArray() before using the index value on it. You might also play with VarGetType() while experimenting.

Getting back to the OP: You said $1 = "XY", but your If statement wasn't changing it to "Z". Maybe there is whitespace before or after, like "XY ". You might try limiting the test value to the first two characters:

$1 = "XY  "
If StringLeft($1, 2) = "XY" Then $1 = "Z"

Or you can remove whitespace first:

$1 = " XY "
If StringStripWS($1, 8) = "XY" Then $1 = "Z"

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Cheers PsaltyDS, I really appreciate your help.

I'm certain there are no spaces or anything like that

I've been trying to change charactors its recognizing correctly also, like its reading "2" as "2" and even trying to change that, amongst others, like "P" and "Q" dont work.

I'm beginning to wonder whether TesseractScreenCapture returnes some sort of constant

I only put that line in with the index on the end to show it was'nt returning an array, I have also tried IsArray and ArrayDisplay.

I'll read up on VarGetType to see if that may help me.

Thanks again


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Big thanks to seangriffin for this, it works a treat.

Can anyone if they have the time, please confirm that a string returned from the screencapture function, cannot be changed ?

I feel I've hit a brick wall here.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Big thanks to seangriffin for this, it works a treat.

Can anyone if they have the time, please confirm that a string returned from the screencapture function, cannot be changed ?

I feel I've hit a brick wall here.

Confirm what? Change it how? Don't be absurd, of course you can change the contents of the string returned:
#include <Tesseract.au3>

Global $Coord, $Capture, $sMsg = ""

Run("Notepad.exe")
WinWait("Untitled - Notepad")
Sleep(2000)
$hNotepad = WinGetHandle("Untitled - Notepad")
$Coord = WinGetPos($hNotepad)
For $n = 0 To 9
    $sMsg &= "This is line " & $n & @CRLF
Next
ControlSetText($hNotepad, "", "[CLASS:Edit; INSTANCE:1]", $sMsg)
Sleep(1000)
$Capture = _TesseractScreenCapture(0, "", 1, 1, $Coord[0] + 10,$Coord[1] + 50, $Coord[0] + 200, $Coord[1] + 200, 0)
If IsArray($Capture) Then
    _ArrayDisplay($Capture, "$Capture")
Else
    ConsoleWrite("String $Capture before = " & $Capture & @LF)
    If StringLeft($Capture, 4) = "This" Then $Capture = "Replaced..."
    ConsoleWrite("String $Capture after = " & $Capture & @LF)
EndIf
WinClose($hNotepad)

Or are you back on some confusion about changing the variable type?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0