我可以将回答随机化到AutoHotKey中的消息框吗?

时间:2016-11-04 19:35:35

标签: autohotkey

我正在编写一个游戏,我需要在某个时刻将答案随机化到消息框中。我的意思是,如果单击是,则有50%的可能性是正确的答案,单击否则也是如此。

这样的事情:

msgBox, 308, Spin!, Try your luck.
   ifMsgBox Yes // replace Yes with function that randomly outputs yes or no here
      {
         msgBox, You're lucky!
      }
      else
      {
         msgBox, Sorry, try again.
      }

我是AHK的初学者 - 基本上,我需要能够将Yes或No传递给ifMsgBox函数。这可能吗?

2 个答案:

答案 0 :(得分:1)

MsgBox, 308, Spin!, Try your luck.

ifMsgBox % myRandomFunction(answer)
  MsgBox Lucky
else
  MsgBox Not Lucky

myRandomFunction(answer)
{
  Random answer, 0, 1
  return answer == 1 ? "Yes" : "No"
}

答案 1 :(得分:0)

您实际上并不需要 ifMsgBox ,因为您忽略了用户的答案。

MsgBox 308, Spin!, Try your luck
Random random_num, 0, 1
MsgBox % random_num == 1 ? "You're lucky!" : "Sorry you lost"
相关问题