2017-01-13 59 views
0

我想在AHK中創建一個多維數組。 callback中的密鑰在Messages陣列中。所有這些處理程序都由菜單執行。我在這裏將對象實例化爲數組:如何將密鑰添加到AutoHotkey中的多維數組中?

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,因爲它沒有將回調/消息保存到它。誰能幫我嗎?謝謝!

P.S - This is my reference to information/documentation.

回答

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