looping variables

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
squishieskull
Newbie
Posts: 2
Joined: Mon Aug 23, 2010 11:00 pm

looping variables

Post by squishieskull » Mon Aug 23, 2010 11:48 pm

how can i use a variable created in a loop.
without using the variable i used to write the name of the variable

if i do message>nColor_%S%
it tells me the value of the variable
but if i write it as nColor_0(one of the values of S)
its value is nColor_0

I've i tried working around it a bit here, however this didnt have any positive effect

Code: Select all

ScreenCapture>0,0,sx,sy,c:\cap\screen.bmp
FindImagePos>C:\cap\rock.bmp,C:\cap\screen.bmp,50,1,XArr8,YArr8,NumFound8
wait>3
if>NumFound8>0
Let>S=0
While>S<NumFound8>XArr8_%S%,YArr8_%S%
LClick
wait>.2
GetPixelColor>XArr8_%S%,YArr8_%S%,nColor_%S%
message>nColor_%S%
wait>2
 Let>S=S+1
EndWhile
wait>1


Let>S=0
Let>base=nColor_%S%
Let>baseX=XArr8_%S%
Let>baseY=YArr8_%S%


//message>base

While>S<NumFound8>base=nColor_%S%
 wait>2
 MouseMove>baseX,baseY
LClick
wait>2
 MouseMove>XArr8_%S%,XArr8_%S%
LClick
//ask>match,yes
endif
 Let>S=S+1
EndWhile

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Aug 24, 2010 9:17 am

You can't do this:

GetPixelColor>XArr8_%S%,YArr8_%S%,nColor_%S%

You can't use that format for the return variable. You will need to do this:

GetPixelColor>XArr8_%S%,YArr8_%S%,gpcResult
Let>nColor_%S%=gpcResult
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

squishieskull
Newbie
Posts: 2
Joined: Mon Aug 23, 2010 11:00 pm

Post by squishieskull » Tue Aug 24, 2010 10:39 am

besides for writing
if>s=0
Let>nColor_%S%=gpcResult_0
endif
if>s=1
Let>nColor_%S%=gpcResult_1
endif
if>s=2
Let>nColor_%S%=gpcResult_2
endif

is there no other way to assign the variables inside the loop?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Aug 24, 2010 10:46 am

Erm. GetPixelColor only returns ONE value. It does NOT return an array. So I'm not sure what you're trying to do here.

You CAN assign variables inside a loop. E.g.:

//example value s...
Let>k=1
Let>val_1=hello

Let>myvar_%k%=val_%k%

This works. But gpcResult_0 does not exist in your case since GetPixelColor only returns one value.

You only need to do:

GetPixelColor>XArr8_%S%,YArr8_%S%,gpcResult
Let>nColor_%S%=gpcResult

If you do that inside your array you will end up with nColor_1, nColor_2, nColor_3 etc for each of XArr_0,YArr_0;XArr_1,YArr_2 etc. Which I think is what you want.

You call GetPixelColor for each of your X and Y array values, and each time if you assign nColor_%S% to the result of GetPixelColor you will end up with the array that you need.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts