samedi 10 février 2018

Lua only complies the first if statement in a while loop

I'm pretty new at programming, but I'm having a problem with the first project I'm trying to write in Lua. I've read a bit of the documentation and tried to implement what I know so far into a program, but there is a problem.

print ("Hello Traveler")
while input ~= "Orc" and "Human" do
  print ("Would you like to be a Human or an Orc?")
  race = io.read()
  if input == "Orc" then
    print ("Orc's are naturally gifted warriors(their base stats are extremely high) but cannot equip most armour and some weapons because of their monstrous size.")
    print ("Are you sure you want to be a Orc?")
    input = io.read()
    elseif race == "Human" then
      print ("Human's are adaptable but naturally weak (they can equip most armour and weapons")
      print ("Will you become a human?")
      input = io.read()
      if input == "Yes" then
        print ("Sweet")
        break
        end
      if input == "No" then
        end
      else
        end
  end

Whenever the user inputs Orc first instead of Human, it just repeats the loop instead of proceeding with the unfinished Orc branch.

I know I'm being a little bit selfish when asking this, but please don't solve this dilemma for me right away, but rather tell me why this is happening and give me pointers in the right direction on how to solve this. I really don't want to copy and paste in code to get the answer, because I'm not learning how to solve this problem but rather how to copy and paste in a solution. Thanks,
- Sam.

Using the online compiler repl.it if that has any relevance

Aucun commentaire:

Enregistrer un commentaire