2017-10-12 147 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