我如何 select 一个随机数组,然后是该数组内的一个随机索引?
How do I select a random array, and then a random index inside THAT array?
;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
}
- 谁能帮我弄清楚(对于 Numpad2::)如何 select 来自欢迎类别的随机谚语数组,然后 select 该(谚语)数组的随机索引?
我尝试抛出一些想法,但结果都只有 "t",因为我没有 return 正确地选择(选择随机数组)[index] 值。
这就是我要做的工作:
;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,这样您就可以验证输出是随机的。
这是您的整个脚本,其中新的随机 select 功能分配给 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]
}
;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
}
- 谁能帮我弄清楚(对于 Numpad2::)如何 select 来自欢迎类别的随机谚语数组,然后 select 该(谚语)数组的随机索引?
我尝试抛出一些想法,但结果都只有 "t",因为我没有 return 正确地选择(选择随机数组)[index] 值。
这就是我要做的工作:
;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,这样您就可以验证输出是随机的。
这是您的整个脚本,其中新的随机 select 功能分配给 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]
}