我正在尝试在AHK中创建一个多维数组。 callback
数组中键的Messages
。所有这些处理程序都由菜单执行。我在这里将对象实例化为数组:
Application = { Messages: [] }
然后我要求用户使用回调,即:规则。然后,用户将一条消息添加到规则数组中。
CreateMessageHandler:
InputBox callback, Create a message group., Choose a callback for this message., ,
if !ErrorLevel
InputBox message, Add a new sentence., Enter your line to store., ,
if !ErrorLevel
Application.Messages[callback].Insert(message)
MsgBox Bravo! Message added successfully.`n`nNote: You can use CTRL+D to quickly display these.
return
然后输出回调,我要求用户输入之前的回调,然后循环显示消息并输出:
DisplayMessageHandler:
InputBox, callback, Display a set of messages., Enter which callback you want to display., ,
if !ErrorLevel
for key, value in Application.Messages[callback] {
send {Raw}%value%
send {Enter}
sleep, 1000
}
return
我没有收到错误,我想不出如何调试Application.Messages
,因为它没有保存回调/消息。谁能帮我吗?谢谢!
答案 0 :(得分:0)
上面的代码试图将消息插入到未设置的数组中,我创建了一个单独的标志,如下所示:
GroupMessageHandler:
InputBox callback, Create a message group., Choose a callback for this message., ,
if !ErrorLevel
Application.Messages[callback] := []
MsgBox % "Successfully added " . callback ". You can how add messages to it!"
return
现在要添加消息,您可以选择回调和消息,它可以Insert
消息到该数组。唯一的限制是我不确定是否存在回调或类型数组。我会调查一下。不管怎样,谢谢。
或者更简单地说,我更改了它,因此当用户说明要使用的组时,它创建了数组的实例(如果它不存在)。我还添加了删除空格,因为键中没有空格。
CreateMessageHandler:
InputBox callback, Which group are you adding., Please enter a callback so you can add more messages to this group., ,
if !ErrorLevel
StringReplace , callback, callback, %A_Space%,,All
if(!Application.Messages[callback])
Application.Messages[callback] := []
InputBox message, Add a new sentence., Enter your line to store., ,
if !ErrorLevel
Application.Messages[callback].Insert(message)
MsgBox Bravo! Message added successfully.`n`nNote: All white spaces of %callback% was removed.`nNote: You can use CTRL+D to quickly display these.
return
我只是在显示器上循环,除了白色空间剥离之外,这里没有任何改变:
DisplayMessageHandler:
InputBox, callback, Display a set of messages., Enter which callback you want to display., ,
StringReplace , callback, callback, %A_Space%,,All
for key, value in Application.Messages[callback] {
send {Raw}%value%
send {Enter}
sleep, 1000
}
return