How do i make a typewriter effect that gets strings from a table one by one
Using string.sub and for loop. On YT we have video about it.
whats the video i literally cant find anything
This is not what i meant, what i meant is:
how do i make the typewriter automatically take out strings from the table and do a typewriter effect on those strings. i am asking to do something like this
local table = {"blah ok", "yeaheayh" , "third word"}
[insert typewriter here that automatically takes out strings from the table and does the effect here]
the tutorial video you’ve shown me doesnt use tables.
Are you trying to perform a typewriter effect on each string as an individual, or the entire table?
i am trying to perform a typewriter effect on each string from the table (so it changes automatically to the next string once it finished using a typewriter effect on the first string of the table)
In the past I’ve used an iterator for this:
local typewrite do
local function iter(s, i)
if i < s:len() then
i = i + 1
return i, s:sub(1, i)
end
end
function typewrite(s)
return iter, s, 0
end
end
You would use it like so:
for _, text in typewrite("my string") do
print(text)
end
For your specific use-case, here’s what I would do:
local messages = {"foo", "bar", "blah"}
for _, s in ipairs(messages) do
for _, text in typewrite(s) do
someLabel.Text = text
-- wait for some amount of time
end
end
You could iterate through the string instead and concatenate the text with the next character,
local goal = "string"
local obj = something.TextLabel
obj.Text = "" -- or just keep it empty initially
for char in goal:gmatch(".") do
obj.Text = obj.Text .. char
wait()
end