Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a text gradually make a sentence?

Asked by
Mystdar 352 Moderation Voter
9 years ago

If I had a string, how would I make the text gradually a string? This is an example I wrote with an array:

String = ["T", "h", "i", "s"]  -- etc

for i in String do
    Text.Text = String[1, i] -- Makes string's text every value from 1 to i
    wait(0.05)
end

This [should] work[s]. But how can I do it with a string? Instead of lots of stings in an array>

String = "This is an example!"
Text = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Text

for i in String do
    Text.Text = i
    wait(0.05)
end

This only makes it the letter one at a time (I think, I can't currently test it) Would I have to put it in an array or is it achievable with a string?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You can't do String[1, i]. If it did work it would probably mean the first element, and then the ith element (as a tuple).


To accumulate the first i elements of String, you would need a loop:

local s = "" -- accumulator
for j = 1, i do
    s = s .. String[j]
end

This is unnecessary, though. Lua provides the :sub function which facilitates what you originally wanted:

String:sub(1, i) -- the first i characters

Thus, you just have to change len repeatedly to see the first len characters of the list:

local text = "This is a message."
for len = 1, #text do
    print(text:sub(1, len))
end
-- T
-- Th
-- Thi
-- This

-- etc...
0
Thanks, about your original statement; you can do this in Python, so I tried in Lua, thank you for the detailed explaination Mystdar 352 — 9y
Ad

Answer this question