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、genrl は、コードの前半で定義されています。例:
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 ステートメントを使用します。