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

Is there a faster way to do this?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
dialog = script.Parent

dialog.Text = "H"
wait(0.1)
dialog.Text = "He"
wait(0.1)
dialog.Text = "Hey"
wait(0.1)
dialog.Text = "Hey "
wait(0.1)
dialog.Text = "Hey y"
wait(0.1)
dialog.Text = "Hey yo"
wait(0.1)
dialog.Text = "Hey you"
wait(0.1)
dialog.Text = "Hey you,"
wait(0.1)
dialog.Text = "Hey you, "
wait(0.1)
dialog.Text = "Hey you, y"
wait(0.1)
dialog.Text = "Hey you, ye"
wait(0.1)
dialog.Text = "Hey you, yea"
wait(0.1)
dialog.Text = "Hey you, yea "
wait(0.1)
dialog.Text = "Hey you, yea y"
wait(0.1)
dialog.Text = "Hey you, yea yo"
wait(0.1)
dialog.Text = "Hey you, yea you"
wait(0.1)
dialog.Text = "Hey you, yea you!"
wait(0.1)
dialog.Text = "Hey you, yea you!"
wait(0.1)
dialog.Text = "Hey you, yea you! "
wait(0.1)
dialog.Text = "Hey you, yea you! D"
wait(0.1)
dialog.Text = "Hey you, yea you! Do"
wait(0.1)
dialog.Text = "Hey you, yea you! Do "
wait(0.1)
dialog.Text = "Hey you, yea you! Do y"
wait(0.1)
dialog.Text = "Hey you, yea you! Do yo"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you "
wait(0.1)
dialog.Text = "Hey you, yea you! Do you r"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you re"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you rem"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you reme"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remem"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you rememb"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remembe"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember "
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember a"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember an"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember any"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anyt"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anyth"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anythi"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anythin"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anything"
wait(0.1)
dialog.Text = "Hey you, yea you! Do you remember anything?"
wait(0.1)

What I'm trying to do is make it so all the text doesn't appear at once, but adds one letter at a time. If you don't get what I mean, it's basically like the Pokemon text, and I was wondering if there was a faster way to do this, or do I have to write each one, one at a time? Thanks for the help!

3 answers

Log in to vote
4
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Solution

Of course there's an easier way to do it. You would want to use string manipulation and a for loop to change the text of the TextLabel (or other object). So to set it up, you want to have a variable set to the message you want. You would then want a numeric for loop which by default adds 1 to the variable i each time it loops through. When setting the value of the text label, you will want to use the sub function of strings to get the text from point a to point b basically.


Final Script

local Message = "Hey you, yea you! Do you remember anything?" --We set the variable here, we will be able to reference it later in the script.
local dialog = script.Parent

for i=1, Message:len() do --The :len() method on Message is what will get how many characters are in the string you defined above. So everything between 1 and however long the string is, the for loop will execute.
    dialog.Text = Message:sub(1,i) --i is basically a variable we defined when creating the for loop, i could be placement or any other means of defining the variable you want. The script is now getting all the characters between 1 and the i variable at the time the loop is executing.
    --1 is added to i automatically in a for loop.
    wait(.1) --This is the wait you wanted.
end --With all for loops, you need an end.

Hopefully this answered your question, if it did do not forget to hit the accept answer button. If you have any questions, feel free to comment below.
0
Thank you so much! And thank you even more for explaining everything in the script! LiquifiedState 90 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Yep!

local text = "Hey you, yea you! Do you remember anything?"

for i = 1, #text do -- #text is length of text
    dialog.Text = text:sub(1, i) -- text:sub(1, i) is only the first through i letters in the string
    wait(.1)
end
0
That didn't seem to work? LiquifiedState 90 — 8y
0
Wow, never refreshed my page xd Shawnyg 4330 — 8y
0
My whole life is a lie, thank you! Fixed YellowoTide 1992 — 8y
0
YOU LIAR YellowoTide 1992 — 8y
0
Thank you soooo much! This makes my life a whole lot easier :) LiquifiedState 90 — 8y
Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

You could use the numeric for loop.

local word = "Hey you, yea you! Do you remember anything?"
dialog = script.Parent
for i=1, string.len(word) do -- run the loop the amount of characters there are
    dialog.Text = string.sub(word,1,i)
    wait(0.1)
end
0
where's shawny's love Shawnyg 4330 — 8y

Answer this question