【问题标题】:How to accept input from command line in Love2d如何在 Love2d 中接受来自命令行的输入
【发布时间】:2021-05-22 12:58:27
【问题描述】:

我在 love2d 中作为服务器编写代码(带有命令行和可视化形式),我如何接受来自命令行的输入?

【问题讨论】:

  • 请提供更多上下文

标签: lua love2d


【解决方案1】:

试试这个...

function love.inp()
-- Building a prompt
 _PROMPT='Input: '
-- Put out the prompt
 io.write(_PROMPT:format())
-- Getting input from stdin
 local result=io.read()
-- Do something with it
 print('Getting:',result)
-- Cleaning up...
 _PROMPT=empty
 result=empty
end

要达到这个功能,试试这个...

love.keyreleased(key)
 if key=="c" then love.inp() end
end

【讨论】:

  • 谢谢,但我应该把这个放在哪里?因为有一个表单,如果我把这个代码块放入update()函数中,表单更新将被暂停。
  • 将正文中的do 替换为love.inp(),并用love.keyreleased(key) if key=="c" then love.inp() end end 为其分配一个键。
  • 如果您使用的是 Windows/Mac,您需要在 conf.lua 中设置 t.console=true 以输出到命令行和从命令行输出 - 看:love2d.org/wiki/Config_Files
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 2019-01-21
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多