我正在尝试做一个if语句来测试变量m是否等于game1或game2,以及它是否显示为两步游戏,以及它的game3或game4是否显示为一步游戏。
game1 = Image[]
game2 = Image[]
game3 = Image[]
game4 = Image[]以上4个变量被分配给4个不同的图像。
m := RandomChoice[{game1, game2, game3, game4}];
If[m === game1 || game2 , InputString["This is a two move game"],
InputString["This is a one move game"]] 这是完全失败的。4个游戏变量被分配给图像,我们需要显示图像并弹出一个输入框
这是我想出的另一个选择,也失败了。
m := RandomChoice[{game1, game2, game3, game4}];
If[m == game1 || game2 , InputString["This is a two move game"]];
If[m == game3 || game4 , InputString["This is a one move game"]]任何帮助都将不胜感激。
发布于 2016-12-13 21:08:01
不能使用以下语法:m === game1 || game2
例如,您应该使用1 == 2 || 1 == 3而不是1 == 2 || 3
但是,您多次使用m,每次使用它时,它都会发生变化。所以你需要修复m,例如
m := RandomChoice[{game1, game2, game3, game4}];
a = m;
If[a == game1 || a == game2 , InputString["This is a two move game"]];
If[a == game3 || a == game4 , InputString["This is a one move game"]]发布于 2016-12-13 22:12:41
moves01 = Thread[{game3, game4} -> "one move game"]
moves02 = Thread[{game1, game2} -> "two move game"]
moves = Association@Catenate[{moves01, moves02}]
m := RandomChoice[{game1, game2, game3, game4}];
moves[m]https://stackoverflow.com/questions/41117944
复制相似问题