ID:156985
 
What is the best way to let text be typed out one letter at a time and have it consider spaces and other punctuation? Would it be better in DM or HTML? Thanks in advance.
Can you extrapolate?
In response to Darkjohn66
I'm not sure how much more I can generalize this. I'd like to know the best way to output text one character at a time.
In response to DisturbedSixx
I am sure you can do something similar with HTML with javascript) or even flash.... but for DM:
proc/output_slow_text(ref, txt)  //  let it be a mob or a list of people, all the same
if(!ref||!txt) return 0 // No ref/text, nothing happens
for(var/i = 1 to length(txt))
ref << output("[copytext(text, i, i+1)]\...", "Slow text.output")
sleep(3) // Here is the key, sleep()! Adjust the time to what you want.


Edit: Can't remember if it was \...[] or []\..., the \... suppresses the new line, so the text are still together.
In response to GhostAnime
It works great thanks but I do have a couple questions. Even when I set sleep(1), it's still a bit too slow for me. Is there a way to make it faster? And also, it seems like it gives very little distance between words. Less then it would normally. Is there a way to fix that?
In response to DisturbedSixx
To add to Ghost's example, if you want it to move faster, simply "step". =)

proc/output_slow_text(ref, txt)  //  let it be a mob or a list of people, all the same
if(!ref||!txt) return 0 // No ref/text, nothing happens
for(var/i = 1 to length(txt) step 2)
ref << output("[copytext(txt, i, i+2)]\...")
sleep(1) // Here is the key, sleep()! Adjust the time to what you want.
ref << ""


On the loop I added a "step 2" which means that i will count upwards of 2 instead of one. Change the copytext from i+1 to i+2 and we're in business. You'll see that's much faster. If you want it even faster, step by 3 and change the copytext to + 3, etc.

I also added ref << "" to fix up an oversight Ghost made, that being the next thing outputted to that output control would be on the same line as the last thing.

And the spaces between words are fine. Append ref << txt to the end of the proc to check for yourself. ;)
In response to Tiberath
Thanks a bunch to both you and Ghost.
DisturbedSixx wrote:
Would it be better in DM or HTML?

I guess that it would define as what you consider better. Both alternatives offer benefits and disadvantages alike. In order to further illustrate I took the liberty to compile a little (quick and dirty) sample.

var/const/SlowText = {"
<html>
<head>
<script type="text/javascript">
var pass = "";
var increment = 0;
var ID, message_length;
var Intervaldelay;
function SlowText(message, latency) {
message_length= message.length;
pass = message;
if(latency >= 20 && latency <= 400) {
Intervaldelay = latency;}
else {
Intervaldelay = 100;}
ID = window.setInterval('DisplayText()', Intervaldelay); }
function DisplayText() {
if(increment <= message_length) {
document.getElementById('foo').innerHTML = pass.substring(0, increment);
increment++;}
else {
window.clearInterval(ID);
increment = 0;}}
</script>
</head>
<body>
<div id="foo">This text can change.</div>
</body>
</html>
"}



mob
Login()
var/t = "ic.dmi"
var/icon/i = new("[t]")
winset(src, "label1", "image=\ref[fcopy_rsc(i)]")
src << browse(SlowText)
..()
verb
SlowTextHTML(var/message as text, var/latency as num)
if(message && latency)
src << output(list2params(list(message, latency)), "browser1:SlowText")

SlowTextOutput(var/message as text)
if(message)
for(var/i=1, i<=length(message), i++)
src << "[copytext(message, i, i+1)]\..."
sleep(1)


The HTML output is client sided and comes with all the benefits of that concept. There is no delay due to high ping (be it server, or network lag), there is no additional stress on the server and you're independent of tick_lag (which means that you can choose the delay in iterations of next to 20 ms and don't have to display 5 letters each 100 ms to simulate the same effect, without editing how fast everything else in your world is being executed).

The 'DM' output is a lot easier to generate and can be used on all BYOND based outputs.
In response to Schnitzelnagler
Thanks for showing both sides and their benefits. I'll consider using both and see which one works the best. Thanks.