关于输入的问题 [英] Begginer question about Input

查看:104
本文介绍了关于输入的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在观看youtube视频以学习Lua,我不明白为什么他在以下代码中使用了tinput而不是输入:



Im watching a youtube video to learn Lua, what I dont understand is why he used tinput instead of input in the following code:

print("Welcome to the game")
input = ""

inv = {"coin", "sword", "armor"}

while imput ~= "exit" do
  print("What do you want to do?")
  input = io.read()
  
  if input == "inspect" then
    print("Youre in a cave. There is an exit.")
  elseif input == "exit" then
    print("You left the cave.")
  elseif input == "inv" then
    for i,v in pairs(inv) do
      print(i,v)
    end
  else
    print("You didnt write a valid command...")
  end
end

input = ""
while input ~= "follow path" do
  print("What do you want to do?")
  input = io.read()
  
  if input == "inspect" then
    print("There is a cave behind you. Youre on a cliff. There is a pathway ahead.")
  elseif input == "follow path" then
    print("You follow the path")
    print("A troll appears wielding an axe")
    print("What do you want to do? (run away, attack)")
    tinput = io.read
    if tinput == "attack" then
      print("You smack with your sword and it falls dead")
    elseif tinput == "run away" then
      etc etc etc..

差异是什么?

推荐答案

这只是另一个变量(收集来自用户通过 io.read )。

请注意,以下行

Is is just another variable (that collects further input from the user via io.read).
Please note, the following line
引用:

而imput〜=exitdo

while imput ~= "exit" do

看起来不正确(我想变量名应该是 input 。这是一个错字吗?)。

doesn't look correct ( I suppose the variable name should be input. Is it a typo?).


仍然有点困惑,但谢谢,我认为这是别的。

是的,它的输入不是我mput,我的错!
Still a little bit confused but thanks, I tought it was something else.
And yes, its input not imput, my fault!


这篇关于关于输入的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆