ASLEvent Typewriter

tl;dr: how would you use the typewriter effect as an ASLEvent?

Before I start, I'ma total amateur (know virtually no code and a lot of words I will misuse here!). Thanks!

Hi! Haven't been on the forums in the while, a while back I made a post about creating wait times in a gamebook, because there didn't really seem to be a simple solution. Everyone was really helpful, and this is eventually what I was presented with!:

eval ("setTimeout(function(){addText(\"<span style='color:Black;font-family:Arial;font-size: 12px'>Hello world!</span>\")}, 1000);")

This printed text in a particular size (12px), font (Arial), and colour (Black), after 1000ms (1 second). It worked really well, exactly how I wanted.

eval ("setTimeout(function(){ASLEvent(\"PrintDelayedLink1\", \"Page2\")}, 1000);")

This would print a page link (Page2) after 1000ms. It went along with a Function that looked like this:

<function name="PrintDelayedLink1" parameters="link">
msg ("{page:"+link+":{color:Black:Click here!}}")
</function>

This was the function, the text of the link would be "Click here!" and the colour, obviously, black. This also worked properly.

I then decided to experiment by creating a typewriter effect to print text. It's already available within a gamebook and very easy to implement normally, but as an ASLEvent I ran into some problems.

This is what I used:

eval ("setTimeout(function(){ASLEvent(\"Typewriter1\"Hello \"100\")}, 3000);")

Along with this:

<function name="Typewriter1">
    TextFX_Typewriter ("Typewriter text.", 100)
  </function>

Nothing happens when I run this. Any ideas?

Thanks!


You can only pass one parameter through an ASLEvent, and there is also an error in the code.

eval ("setTimeout(function(){ASLEvent(\"Typewriter1\"Hello \"100\")}, 3000);")

Take this part by itself: ASLEvent(\"Typewriter1\"Hello \"100\")

An ASLEvent should be formatted thusly: ASLEvent("FunctionName","single_parameter")

You have to use a backslash \ to cancel out a double-quotation mark " inside of the JS.eval() function, so that example would look like this in the "field" (if you use double quotation marks inside of your JS.eval() functions):

JS.eval("ASLEvent(\"FunctionName\",\"single_parameter\");")

I, personally, have taken to using single quotation marks inside of such functions (i.e., msg(), JS.eval()), so I need not worry with backslashes. that would look like this:

JS.eval("ASLEvent('FunctionName','single_parameter');")

I find that using single quotation marks (') is much less confusing, transferable between projects, and it just looks cleaner.


Now...

It looks like you want to print "Hello" with a 100 millisecond delay between letters, and you want the message to begin 3 seconds after calling the function?

Let's start with your function, though.

Let's change a few things:

  <function name="TypeFxCustom" parameters="param">
    params = Split(param,"|")
    text = params[0]
    time = params[1]
    time = ToInt(time)
    TextFX_Typewriter (text, time)
  </function>

Note that we are using | to separate our text parameter from our time parameter.


To call that function normally (with no SetTimeout() & not from a JS function, but from a normal Quest script):

TypeFxCustom ("Hello.|100")

To call that function normally, but using a SetTimeout() (still not from a JS function):

      SetTimeout (3) {
        TypeFxCustom ("Hello.|100")
      }

NOTE: The only reason to create and use that function would be to call it from JS, using an ASLEvent. I was only providing examples so you could see exactly what was going on.


To do exactly what you want to do (as posted), using JS:

JS.eval("setTimeout(function(){ASLEvent('TypeFxCustom','Hello.|100');},3000);")

Log in to post a reply.

Support

Forums