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

how to make Appearing letters?

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

Hey i'm making a game and I need something. After you step on a certain brick a little message will appear saying: Hello and welcome to the world! I don't want to it to just appear though, I want it to appear letter by letter if that makes sense.

Like for example the letters will show up like this only it wont appear in rows it will happen all in 1 row. I don't want to have to add a letter every time so if you know an easy way to do this please tell me! W We Wel Welc Welco etc. i want it efficient though

message.Text=W
message.Text=We
message.Text=wel
message.Text=welc
message.Text=welco
message.Text=welcom
message.Text=welcome

1 answer

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

Let's say we have a finished string message. If we want to build the version of it growing one letter at a time, there's essentially two approaches that are very similar:

  • Grow the text by the ith character
  • Use the substring of the first i characters

They look like this:

Growing:

text = ""
for i = 1, #message do
    text = text .. message:sub(i,i)
    print(text)
end

Substring:

for i = 1, #message do
    text = message:sub(1,i)
    print(text)
end

I find the second approach to be much more elegant.

Ad

Answer this question