我的代码不断循环 [英] My code keeps looping
本文介绍了我的代码不断循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Lua还是很陌生,我的代码让我感到困惑,我在做迷宫游戏只是为了练习,每次运行代码时,我都会遇到一个错误,它会循环执行,而不是转到下一个部分.我将不胜感激.
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.
我的代码:
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
推荐答案
尽管这里的逻辑有些偏斜(一旦您掉头
,您将被要求进行检查
或 leave
再次),这是您进入第二部分的方式-如果您选择检查
迷宫,则需要进行第二部分:
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
这篇关于我的代码不断循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文