Jump to content
Macro Express Forums

Why doesn't this array variable work?


Recommended Posts

This macro is one of the few in which I've used variable arrays, so I expect it's down to me. But if so, could someone identify my mistake please?

 

The macro should simply capture 99 pixel values of a point that is constantly changing, one every tenth of a second. It should store them in N[1], N[2], N[3] .... N[99]. My variable %Snapshot% is defined under Integer Variables and is 'available to macros'. Before running it there are no error messages. Yet it finishes in under a second instead of about 10 and in the Debugger I then get this message about the Get Pixel command:

"Debug Error: Undefined variable or the variable is the wrong type"

Repeat Until %Snapshot% Equals "99"

Get Pixel Color from Beneath the Mouse into %N[%Snapshot%]%

Text Box Display:

Variable Modify Integer %Snapshot%: Increment

Delay: 100 milliseconds

End Repeat

Text Box Display:

 

<REPEAT UNTIL Variable="%Snapshot%" Condition="\x00" Value="99"/>
<GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%N[%Snapshot%]%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Snapshot = \\f1 %Snapshot%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%Snapshot%"/>
<DELAY Flags="\x02" Time="100"/>
<END REPEAT/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %N[1]%\r\n\\par %N[\\f1 2\\f0 ]%\r\n\\par %N[\\f1 3\\f0 ]%\r\n\\par %N[\\f1 4\\f0 ]%\r\n\\par %N[\\f1 5\\f0 ]%\r\n\\par %N[\\f1 6\\f0 ]%\r\n\\par %N[\\f1 7\\f0 ]%\r\n\\par %N[\\f1 8\\f0 ]%\r\n\\par %N[\\f1 9\\f0 ]%\r\n\\par %N[\\f1 10\\f0 ]%\r\n\\par %N[1\\f1 1\\f0 ]%\r\n\\par %N[1\\f1 2\\f0 ]%\r\n\\par %N[1\\f1 3\\f0 ]%\r\n\\par %N[1\\f1 4\\f0 ]%\r\n\\par %N[1\\f1 5\\f0 ]%\r\n\\par %N[1\\f1 6\\f0 ]%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

It took some gymnastics to get that Get Pixel command constructed. You can't do it where you would expect, namely in the initial creation of the variable, by typing it inside the square brackets of N[]. But it looks OK to me. So what's up please?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Consider the first time you enter the loop. As you haven't initialized %Snapshot%, its value is zero. So you're executing this command:

Get Pixel Color from Beneath the Mouse into %N0%

 

There's no such variable, since N variables go from N1 to N99.

 

If you first set %Snapshot% to 1, it all works as expected.

Link to comment
Share on other sites

Consider the first time you enter the loop. As you haven't initialized %Snapshot%, its value is zero. So you're executing this command:

Get Pixel Color from Beneath the Mouse into %N0%

 

There's no such variable, since N variables go from N1 to N99.

 

If you first set %Snapshot% to 1, it all works as expected.

I second Paul's solution. You've got a few options, too.

 

You could simply define %Snapshot% before beginning the repeat loop; however, my preferred method would be this:

 

Repeat Start (Repeat 99 times) // Store counter in %Snapshot%
 Get Pixel Color from Beneath the Mouse into %N[%Snapshot%]%
 Text Box Display: 
 Delay: 100 milliseconds
End Repeat
Text Box Display:

 

<REPEAT START Start="1" Step="1" Count="99" Save="TRUE" Variable="%Snapshot%"/>
<GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%N[%Snapshot%]%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Snapshot = \\f1 %Snapshot%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<DELAY Flags="\x02" Time="100"/>
<END REPEAT/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %N[1]%\r\n\\par %N[\\f1 2\\f0 ]%\r\n\\par %N[\\f1 3\\f0 ]%\r\n\\par %N[\\f1 4\\f0 ]%\r\n\\par %N[\\f1 5\\f0 ]%\r\n\\par %N[\\f1 6\\f0 ]%\r\n\\par %N[\\f1 7\\f0 ]%\r\n\\par %N[\\f1 8\\f0 ]%\r\n\\par %N[\\f1 9\\f0 ]%\r\n\\par %N[\\f1 10\\f0 ]%\r\n\\par %N[1\\f1 1\\f0 ]%\r\n\\par %N[1\\f1 2\\f0 ]%\r\n\\par %N[1\\f1 3\\f0 ]%\r\n\\par %N[1\\f1 4\\f0 ]%\r\n\\par %N[1\\f1 5\\f0 ]%\r\n\\par %N[1\\f1 6\\f0 ]%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

By using Repeat Start rather than Repeat Until, you still get to specify 99 iterations. But since you're storing the counter in %Snapshot%, you never have to define Snapshot = 1 and you never have to use the Modify Variable Increment command on Snapshot, as the Counter will increment it automatically. So you eliminate two steps by combining them all within the Repeat Start command.

 

That's my suggestion.

Link to comment
Share on other sites

I second Paul's solution. You've got a few options, too.

 

You could simply define %Snapshot% before beginning the repeat loop; however, my preferred method would be this:

[code
<REPEAT START Start="1" Step="1" Count="99" Save="TRUE" Variable="%Snapshot%"/>
<GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%N[%Snapshot%]%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Snapshot = \\f1 %Snapshot%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<DELAY Flags="\x02" Time="100"/>
<END REPEAT/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %N[1]%\r\n\\par %N[\\f1 2\\f0 ]%\r\n\\par %N[\\f1 3\\f0 ]%\r\n\\par %N[\\f1 4\\f0 ]%\r\n\\par %N[\\f1 5\\f0 ]%\r\n\\par %N[\\f1 6\\f0 ]%\r\n\\par %N[\\f1 7\\f0 ]%\r\n\\par %N[\\f1 8\\f0 ]%\r\n\\par %N[\\f1 9\\f0 ]%\r\n\\par %N[\\f1 10\\f0 ]%\r\n\\par %N[1\\f1 1\\f0 ]%\r\n\\par %N[1\\f1 2\\f0 ]%\r\n\\par %N[1\\f1 3\\f0 ]%\r\n\\par %N[1\\f1 4\\f0 ]%\r\n\\par %N[1\\f1 5\\f0 ]%\r\n\\par %N[1\\f1 6\\f0 ]%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
[/code]

 

Rather than telling the Repeat to loop until Snapshot = 99, just set the loop to repeat 99 times and store the counter in variable %Snapshot%. This way, Snapshot gets defined with each loop, you never have to manually increment it, because the increment happens automatically with each iteration of the loop. You also don't have to define Snapshot = 1 before beginning the repeat loop, because the first pass of the repeat will automatically define Snapshot as 1. So you eliminate two steps by combining them all within the Repeat Start command.

 

Thanks both - embarassingly obvious slip! :)

 

I'll implement that neat improvement too, Steve, thank you.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...