2017-10-12 192 views
2
;Sayings 
friendly := ["hello there!", "Howdy!", "Greetings friend!", "hi there"] 
helpful := ["x next to y and z", "this is helpful", "The sky is blue"] 
other := ["where is my toaster", "do it", "just"] 

;Categories 
welcome := [[friendly][helpful][other]] 

Numpad0:: 
    intotext(randomfromarray("friendly"),50,35,15) 
    return 

Numpad1:: 
    intotext(randomfromarray("helpful"),50,35,15) 
    return 

;Numpad2:: 
    ;Select a random saying from the welcome category. 

intotext(whatisit,thekeydelay,introwait,outrowait) 
{ 
    SetKeyDelay, thekeydelay 
    Send, t 
    Sleep, %introwait% 
    Send, %whatisit% 
    Sleep, %outrowait% 
    Send, {enter} 
} 

randomfromarray(uniquepickof){ 
    return %uniquepickof%[random(1, %uniquepickof%.maxindex())] 
} 

random(x, y){ 
    Random, var, %x%, %y% 
    return var 
} 
  1. 有人可以幫我找出(用於NUMPAD2::)如何從Welcome類隨機熟語陣列,然後選擇(說)陣列的隨機指標?

我試着拋出一些想法,但它們都是隻有「t」,因爲我沒有正確返回(pick random array)[index]值。如何選擇一個隨機數組,然後在THAT數組中選擇一個隨機索引?

回答

0

因此,這裏是我得到了什麼工作:

;Sayings 
friendly := ["hello there!", "Howdy!", "Greetings friend!", "hi there"] 
helpful := ["x next to y and z", "this is helpful", "The sky is blue"] 
other := ["where is my toaster", "do it", "just"] 

;Categories 
welcome := [friendly, helpful, other] 

Random, randNumOne, 1, welcome.MaxIndex() 

MsgBox % "Your random number is for array is: " . randNumOne 

randArray := welcome[randNumOne] 

Random, randNumTwo, 1, randArray.MaxIndex() 

MsgBox % "Your random Saying is " . randArray[randNumTwo] 

爲了簡化,我刪掉了實際只是一個包裝您的自定義功能,內置Random功能。我離開了MsgBox,以便您可以驗證輸出是隨機的。

這是你分配給NUMPAD2按鍵新的隨機選擇功能完整的腳本:

;Sayings 
friendly := ["hello there!", "Howdy!", "Greetings friend!", "hi there"] 
helpful := ["x next to y and z", "this is helpful", "The sky is blue"] 
other := ["where is my toaster", "do it", "just"] 

;Categories 
welcome := [friendly, helpful, other] 

Numpad0:: 
    intotext(randomfromarray("friendly"),50,35,15) 
    return 

Numpad1:: 
    intotext(randomfromarray("helpful"),50,35,15) 
    return 

Numpad2:: 
    Random, randNumOne, 1, welcome.MaxIndex() 

    MsgBox % "Your random number is for array is: " . randNumOne 

    randArray := welcome[randNumOne] 

    Random, randNumTwo, 1, randArray.MaxIndex() 

    MsgBox % "Your random Saying is " . randArray[randNumTwo] 
    return 

intotext(whatisit,thekeydelay,introwait,outrowait) 
{ 
    SetKeyDelay, thekeydelayt 
    Send, t 
    Sleep, %introwait% 
    Send, %whatisit% 
    Sleep, %outrowait% 
    Send, {enter} 
} 

randomfromarray(array) 
{ 
    Random, rand, 1, array.MaxIndex() 

    return array[rand] 
} 
+0

謝謝!我修改了一些東西,並將一個(類別)arg添加到randomfromarray中,並將if語句返回給randarray [randsaying]。 \t如果貓{ \t \t隨機,RAND 1,1,%獨特%.maxIndex() \t \t randArray:=%獨特%[RAND 1] \t \t隨機,randSaying,1,randArray.MaxIndex()\t \t \t return randArray [randSaying] \t} – SimpleDudeX

+0

太棒了!我有一個關於你的代碼的問題:你有什麼'intotext'函數?當我正在處理腳本時,我做了一些非常奇怪的事情,所以我不得不對它進行評論,直到我完成 –

+0

intotext是一種將所選語句鍵入遊戲文本框的功能,打開聊天框的熱鍵是發送「t」,等待時間延遲。 – SimpleDudeX