if statement - Elseifs being skipped in Lua -
i started work on little game-dev project in lua, , having trouble part of code:
if genrel == rpg , langl == basic , topicl == war review = math.random(2, 5) review2 = math.random(2, 5) review3 = math.random(2, 3) money = money + 300 print("you have earned total of $300 dollars game. overall not many people enjoyed game.") elseif genrel == rpg , langl == basic , topicl == "western" review = math.random(7, 9) review2 = math.random(4, 9) review3 = math.random(5, 8) money = money + 400 print("you have earned total of $300 dollars game. game recieved mixed reviews.")
topicl, langl, , genrel, defined earlier in code. example:
topicchoice = io.read() if topicchoice == 'war' topic = "[war]" topicl = war proglang = io.read() if proglang == 'java' lang = "[java]" langl = java genrechoice = io.read() if genrechoice == 'action' genre = "[action]" genrel = action
everything defined, when run code random numbers outputted first ones under if, no matter put in. may hard understand, here full code. http://pastebin.com/xs3aevfs
summary: program decides random numbers shown determining genre, topic, , coding language are. instead of selecting numbers genre, topic, , coding language, uses first if statement.
early in code have this:
if genrechoice == 'action' genre = "[action]" genrel = action elseif genrechoice == 'rpg' genre = "[rpg]" genrel = rpg elseif genrechoice == 'sim' genre = "[sim]" genrel = sim end
and assign genrel
value of variables action
, rpg
, sim
, variables don't appear have been defined anywhere, value nil
. in other words when execute:
genrel = action
is same if did:
genrel = nil
Comments
Post a Comment