Это мой первый написанный код, потому что я только что начал, поэтому я не уверен, что что-то отступом правильно. Но я хочу, чтобы можно было повторять текст, но я не уверен, как это сделать.Как повторить код в Lua?
print("Hey there. I want to play a game.")
print("Tell me your name")
print("Type your name")
name = io.read()
print("Oh, what a nice name. I was gonna call my kid the same")
print("Ok. So as you can see, there are no ligths here. It's all dark. You have three choices. Go west, go east, go north.")
print("To go North, type 'n'. To go East, type 'e'. to go West, type 'w'.")
repeat
direction = io.read()
if direction == "w" then
print(" You see a light switch.")
print(" type 'switch'to turn on the switch.")
print(" type 'go_back' to turn around")
best = io.read() -- This is where i want it to be able to repeat
end
if best == "switch" then
print(" The light goes on.")
print(" As the light glows stronger, you see someone standing infront of you")
print("Before you know it, he slits your throat. Want to try again?")
print("Press enter to try again")
try_again = io.read()
best = io.read()
direction = io.read()
elseif best == "switch" then
print(" The light goes on.")
print(" As the light glows stronger, you see someone standing infront of you")
print("Before you know it, he slits your throat. Want to try again?")
print("Press enter to try again")
try_again = io.read()
end
end
until best ~= "go_back" -- to repeat the code up above
типа 'как повторить код в lua' в Google – zeromus
Если вы отступы ваш код правильно, это покажет, есть дополнительный' 'end' до того until'. О повторении кода вставьте строки, которые вы хотите повторить в функцию, и вызовите их по мере необходимости. Найдите «многострочные строки» в Lua, это может быть удобно. –