38312

My code keeps looping

I'm very new to Lua and my code is confusing me, I'm making a maze game just for practise and I've come across an error, everytime I run my code it loops, instead of going to the next part. I will appreciate any help given.

My code:

print ("Welcome to the maze") input = "" while input ~= "leave" do print ("What do you want to do first? Leave or inspect?") input = io.read() if input == "inspect" then print (" You venture towards the maze.") end if input == "leave" then print ("You turn around and run.") end end input = "" while input ~= "turn around" do print ("There is a path, which do you want to take, left, right or turn around?") input = io.read() if input == "left" then print (" You turn left to the dark trees.") end if input == "right" then print ("You turn right to the light pathway.") end if input == "turn around" then print ("You turn around and run.") end end

Answer1:

Although the logic here is slightly skewed (once you turn around you'll be asked to inspect or leave again), here's how you would get to that second part - it needs to occur if you choose to inspect the maze:

print ("Welcome to the maze") input = "" while input ~= "leave" do print ("What do you want to do first? Leave or inspect?") input = io.read() if input == "inspect" then print (" You venture towards the maze.") while input ~= "turn around" do print ("There is a path, which do you want to take, left, right or turn around?") input = io.read() if input == "left" then print (" You turn left to the dark trees.") end if input == "right" then print ("You turn right to the light pathway.") end if input == "turn around" then print ("You turn around and run.") end end end if input == "leave" then print ("You turn around and run.") end end

Recommend

  • Splitting a csv file into panda dataframe by multiple columns
  • How to upload video to Vimeo through their api?
  • Creating grails binary plugin results in jar file wich contains all groovy files with comments
  • C#, Updating a Progress Bar Using Background Worker From a Different Class
  • Java NoClassDefFoundError when running jar containing library jar
  • How to reduce the time delay to reach run method of Runnable class using ExecutorService Java
  • R encoding ASCII backtick
  • Ruby: Invert a hash to also preserve non unique values
  • Why do native C++ projects have a TargetFrameworkVersion?
  • Sending dynamic email reminders in Ruby on Rails?
  • How can I see Python's __builtins__ source code?
  • chrome PDF viewer can't download file
  • Grails eager fetch doesn't retrieve all data
  • C# Remove URL from String
  • Weird LEFT OUTER JOIN on Includes eager loading of rails 3
  • Persistent stty Settings?
  • How does ActiveSupport do month sums?
  • Entity Framework ObjectContext: Concurrency
  • Want to understand iframe breakout code
  • pandas computation in each group
  • Excel VBA How to populate a multi-dimensional (3d) array with values from multiple excel ranges?
  • Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Record samples being played with OpenAL
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • What is Eclipse's Declaration View used for?
  • Perl system calls when running as another user using sudo
  • what is the difference between the asp.net mvc application and asp.net web application
  • Jquery - Jquery Wysiwyg return html as a string
  • align graphs with different xlab
  • Return words with double consecutive letters
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Matrix multiplication with MKL
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Append folder name and increment by 1 using batch script
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Python/Django TangoWithDjango Models and Databases