Lua - 如何在一个打印语句中打印 2 个东西
Lua - How to print 2 things in one print statement
在 python 中,您可以通过键入
使用一个语句来打印 2 个内容
print("Hello" + " World")
输出将是 "Hello world"
那么在 Lua 中是否有简单的方法可以再次执行此操作?
我正在尝试让语句打印百分比和百分号。这是我目前拥有的
function update()
local hp = crysHu.Health/ crysHu.MaxHealth
local text = script.Parent.TextLabel
healthBar:TweenSize(UDim2.new(hp,0,1,0),"In","Linear",1)
text.Text = math.floor(hp*100)
end
text.Text = math.floor(hp*100)
是我需要帮助的部分,仅供参考。
做 text.Text = (math.floor(hp*100) + "%"
) 不起作用。
使用 ,
。 Lua 和 Python 都一样,尽管 Lua 在它们之间放置了一个制表符 print
:
print(2, 3) # 2 3
或者使用 io.write
但是你需要处理换行符。
io.write("hello", " world\n") # hello world
如果您要进行简单的字符串操作,可以像这样将它们与 ..
连接起来:
local foo = 100
print( tostring(foo) .. "%") -- 100%
或者如果您想要更具体的格式,您可以使用 string.format
local foo = 100
print( string.format("%d%%", foo)) -- 100%
在 python 中,您可以通过键入
使用一个语句来打印 2 个内容print("Hello" + " World")
输出将是 "Hello world"
那么在 Lua 中是否有简单的方法可以再次执行此操作?
我正在尝试让语句打印百分比和百分号。这是我目前拥有的
function update()
local hp = crysHu.Health/ crysHu.MaxHealth
local text = script.Parent.TextLabel
healthBar:TweenSize(UDim2.new(hp,0,1,0),"In","Linear",1)
text.Text = math.floor(hp*100)
end
text.Text = math.floor(hp*100)
是我需要帮助的部分,仅供参考。
做 text.Text = (math.floor(hp*100) + "%"
) 不起作用。
使用 ,
。 Lua 和 Python 都一样,尽管 Lua 在它们之间放置了一个制表符 print
:
print(2, 3) # 2 3
或者使用 io.write
但是你需要处理换行符。
io.write("hello", " world\n") # hello world
如果您要进行简单的字符串操作,可以像这样将它们与 ..
连接起来:
local foo = 100
print( tostring(foo) .. "%") -- 100%
或者如果您想要更具体的格式,您可以使用 string.format
local foo = 100
print( string.format("%d%%", foo)) -- 100%