如何使用lua中的for循环将字符串转换为列表以进行索引?

问题描述 投票:0回答:1

我正在尝试制作一个 roblox 游戏,我需要一个 gui 来逐个字符地显示文本,但它只显示数字,这是我的代码

local frame = script.Parent.Parent
local currentText = ""
frame.Visible = false

local function showText (text, delayBetweenChanges)
    frame.Visible = true
    for letter in string.split(text,"") do
        local currentText = (currentText .. letter)
        script.Parent.Text = currentText
        wait(delayBetweenChanges)
    end
end

我认为它会将下一个字符添加到已经存在的字符串中,然后显示最终的字符串

但它显示了与该字符在字符串中的位置相关的数字

string lua roblox
1个回答
0
投票

local label=script.Parent
local frame=label.Parent
frame.Visible=false
local function showText (text,delayBetweenChanges)
    frame.Visible=true
    label.Text=""
    for _,letter in ipairs(text:split"")do
        label.Text+=letter
        wait(delayBetweenChanges)
    end
    --frame.Visible=false
end

© www.soinside.com 2019 - 2024. All rights reserved.