1
votes

In a loop I want to use a counter to use different variables. The problem is that both use the % symbol: %VAR%

Showing where I get the error %%, Simplified:

textGH1 = Peter
textGH2 = rocks.

i = 1
Loop, 2
{
SendInput {Enter}
Sleep 50
SendInput, %textGH%i%%
Sleep 50
SendInput {Enter}
i++
} 

Error: Empty variable reference %%

What I tried: I have looked up arrays for autohotkey, but I only found pseudo-arrays using the %COUNTER% as a workaround, similiar to how I did it. Second, I have assigned a variable in the loop to your current variable:

text := textGH%i%

However this doesn't call the variable, as expected (needed %textGH%i%% again)

2

2 Answers

1
votes

I think I understand what you are trying? Swap variables when the counter changes. Easiest way to do this is with an Array.

Here's a solution for you play with:

Define Array. Array's Index values automatically, so Peter is at Index 1 Rocks is at Index 2.

MyArray := ["Peter", "Rocks"]

Loop amount of times as there are Values in your Array.

Loop, % MyArray.MaxIndex() {  

SendInput {Enter}   
Sleep 50  

Send your Array at [Index] A_Index is a built in counter for Loops.

SendInput % MyArray[A_Index]   

Sleep 50    
SendInput {Enter} 
}

Hope this helps.

0
votes

This should work:

SendInput, %textGH%%i%