Do not support this code writing method?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Gaik
Posts: 25
Joined: 14 Jan 2024, 10:05

Do not support this code writing method?

Post by Gaik » 17 Jan 2024, 14:36

我现在遇见问题了,我想使用loop或for进行编写,缩短代码体积。
[Mod edit: Added translation of the text above:]
DeepL wrote:I'm having problems now, I want to write using loop or for to shorten the code size.

Code: Select all

MsgBox Self_array1[A_Index] . Self_array2[A_Index] . Self_array1[A_Index] . "_de"
The above methods can run smoothly. But at the bottom, there was an error.

Code: Select all

    Global delay1 := ""
    Global delay2 := ""
    Global delay3 := ""
    Global delay4 := ""
    Global delay5 := ""
    Global delay6 := ""
    Global delay7 := ""
    Global delay8 := ""

    Global colour1 := ""
    Global colour2 := ""
    Global colour3 := ""
    Global colour4 := ""
    Global colour5 := ""
    Global colour6 := ""
    Global colour7 := ""
    Global colour8 := ""

    Self_array1 := ["Q", "W", "E", "R", "A", "S", "D", "F"]
    Self_array2 := ["1", "2", "3", "4", "5", "6", "7", "8"]
    Self_array3 := ["delay1","delay2","delay3","delay4","delay5","delay6","delay7","delay8"]
    Self_array4 := ["colour1","colour2","colour3","colour4","colour5","colour6","colour7","colour8"]


               delay%[A_Index]% := IniRead(FileName, Self_array1[A_Index] . "_dd", "de")
                colour%[A_Index]% := IniRead(FileName, Self_array1[A_Index] . "_cc", "cr")
I hope to receive everyone's help. If not, then I will only have to write line by line。
Thank you everyone

coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Do not support this code writing method?

Post by coffee » 17 Jan 2024, 14:54

a_index only works inside a loop. There's no loop statement anywhere.
Besides that, delay%[a_index]% should probably be delay%a_index%, no square brackets.
But autohotkey has had the technology to not need pseudo arrays since 100 years ago.
So you could in theory do delay := [] as initializer, then delay[a_index] := iniRead(...., then use it like delay[3] etc, all the delayN variables would just be one delay variable holding the Array.

Gaik
Posts: 25
Joined: 14 Jan 2024, 10:05

Re: Do not support this code writing method?

Post by Gaik » 17 Jan 2024, 15:41

coffee wrote:
17 Jan 2024, 14:54
a_index only works inside a loop. There's no loop statement anywhere.
Besides that, delay%[a_index]% should probably be delay%a_index%, no square brackets.
But autohotkey has had the technology to not need pseudo arrays since 100 years ago.
So you could in theory do delay := [] as initializer, then delay[a_index] := iniRead(...., then use it like delay[3] etc, all the delayN variables would just be one delay variable holding the Array.
Yes, working in a loop, but reporting an error. I forgot to copy the loop in the demonstration code I submitted

coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Do not support this code writing method?

Post by coffee » 17 Jan 2024, 21:09

Try changing delay%[a_index]% to delay%a_index%, if you still want to use pseudo arrays. That should at least get rid of one error.

Post Reply

Return to “Ask for Help (v2)”