我开始在 Lua 中开发一个小型 Game-Dev 项目,但我的这部分代码遇到了问题:
if genrel == RPG and langl == BASIC and topicl == WAR then
review = math.random(2, 5)
review2 = math.random(2, 5)
review3 = math.random(2, 3)
money = money + 300
print("You have earned a total of $300 dollars from your game. Overall not many people enjoyed the game.")
elseif genrel == RPG and langl == BASIC and topicl == "WESTERN" then
review = math.random(7, 9)
review2 = math.random(4, 9)
review3 = math.random(5, 8)
money = money + 400
print("You have earned a total of $300 dollars from your game. The game recieved mixed reviews.")
topicl、langl 和genrel 是在代码前面定义的。例子:
topicChoice = io.read()
if topicChoice == 'War' then
topic = "[War]"
topicl = WAR
progLang = io.read()
if progLang == 'Java' then
lang = "[JAVA]"
langl = JAVA
genreChoice = io.read()
if genreChoice == 'ACTION' then
genre = "[ACTION]"
genrel = ACTION
一切都已定义,但是当我运行代码时,无论我输入什么,输出的随机数都是 if 下的第一个。这可能很难理解,所以这是我的完整代码。 http://pastebin.com/XS3aEVFS
摘要:程序通过确定类型、主题和编码语言来决定显示哪些随机数。它没有按类型、主题和编码语言选择数字,而是简单地使用第一个 if 语句。