Can I nest the SetTimeOut function?

Silver
I'm sure this must be obvious, if do-able. Basically I'm using the typewriter effect to return a string that includes player input. Presently a snippet of it looks like this:

  TextFX_Typewriter ("You are " + CapFirst (LCase (player.forename)) + " " + CapFirst (LCase (player.surname)) + ": yes / no?", 100) 
SetTimeout (4) {
msg ("")
request (Show, "Command")


What I want to happen is for the string to be typed and then the command bar appears. As you can see, I gave four seconds for this to happen - which was fine in experiments using my name. But if they typed forename: Englebert Surname: Humperdinck then the command bar would appear prematurely. Is there any way of getting the command bar to appear after the text is typed, perhaps by nesting the SetTimeout or by other means?

Alex
Using get input perhaps?http://docs.textadventures.co.uk/quest/scripts/get_input.html

Silver
I've done that side of it. Maybe I didn't explain myself properly. Basically the TextFX_Typewriter spends a certain amount of time writing out the msg. I want the command bar to re-appear after that has happened. Presently I have it timed for four seconds but that assumes it will take that time or less. Is there no way for the TextFX_Typewriter function to finish and then show the command bar avoiding the SetTimeout thiong which is a guess?

Alex
I don't think so, unless you adapted the JavaScript it calls to raise an ASLEvent when it's done. That's probably overkill so the SetTimeout approach is probably best here, though it's a bit annoying that you have to work out how long it has to wait for the typewriter effect to finish.

Silver
I see. I guess adding a second to the SetTimeout will have to suffice to cover all bases and hope people don't want to play as someone with a really long name. And if they do, they'll just see weaknesses in my code rather than anything game breaking. And those with a shorter name will have to wonder what's going on for a second longer.

Or

I could not do that bit using that text effect. It fits nicely with the story arc though, coaxing their chosen name out of them by means of logging onto a computer in real time.

Silver
Actually, that's maybe the solution - to not use the text effect on that bit. The player won't question it and it'll look less clunky.

HegemonKhan
The question seems to be, is there anything that will wait for the TypeWriterEffect to finish first (or is there a way to set such a 'done' check~boolean~string within the TypeWriterEffect), which I'd assume Alex understands and would have answered yes, if there was, lol.

We can wait upon scripts to finish, but the TypeWriterEffect itself seems to run independantly (while its script has already finished), and so, there seems to be no way of thus waiting for it to finish.

-----

probably best option is to give a limit on the length of the name and to give enough time for the typewrittereffect to finish and just to provide a 'lull' time for the person playing the game to wait for the TypeWritterEffect to finish (heck, even provide a 'msg' saying~telling the person to wait for it to finish, lol).

----

things you can try:

'on ready', 'wait'

'handled', or 'whatever label you prefer' (Boolean~String~Integer, aka a Flag, Variable) design (example, a poor one):

fight_handled = false
if (orc.dead = true) {
-> fight_handled = true
}
if (fight_handled = true) {
-> // loot corpse
} else if (fight_handled = false) {
-> // loop~do fight scripting again

Silver
This was the problem I was having. The string the typewriter returns includes player.forename and player.surname which I have no control over. It worked fine in my test if someone was called Joe Bloggs (not my name, but the same amount of letters). But if they were called Englebert Humperdink it obviously takes more time to write that out and the command bar would appear prematurely. To solve it I'm not going to use the text effect for that bit. And it still fits as they're inputting to a simulated piece of software, so it can't be 'wrong'.

Silver
I did think about setting a boolean, but it'd still check too soon.

HegemonKhan
something you could do...

if (LengthOf (player.forename) + LengthOf (player.surname) < 10) {
-> settimeout (10)
} else if (LengthOf (player.forename) + LengthOf (player.surname) >= 10) {
-> settimeout (20)
} else if (LengthOf (player.forename) + LengthOf (player.surname) >= 30) {
-> settimeout (30)
}
// you get the idea

-----

though... if you can adjust (put) Attributes (such as 'player.fore~sur-name') into the TypeWriterEffect (I haven't worked with this yet myself ~ so just going by what I'm reading in this thread, lol), and even be able to Return values, then you indeed can have it have a 'check' for when it is done...

(no idea on the correct syntax...lol)

handled = false
TypeWriterEffect ("blah blah blah blah blah blah" + command:return{handled = true} )
if (handled = true) {
-> // blah1
} else if (handled = false) {
-> // not sure how to create a 'pause~wait' effect for the person playing the game (this will require it's own creativity or research, lol)

Pertex
HegemonKhan wrote:something you could do...

if (LengthOf (player.forename) + LengthOf (player.surname) < 10) {
-> settimeout (10)
} else if (LengthOf (player.forename) + LengthOf (player.surname) >= 10) {
-> settimeout (20)
} else if (LengthOf (player.forename) + LengthOf (player.surname) >= 30) {
-> settimeout (30)
}
// you get the idea


That will not work correctly. There are differences between Quest-Player, Mobile-Player and playing in a browser. Even different browsers and operating systems react different. And then there is a problem with the typewriter. The more text you output the slower the effect becomes.

Silver
Yeah, I came across that. Initially the whole start up game blurb was going to be output using the typewriter effect. Even set at 1 millisecond it dragged to slower than reading speed and I found myself drumming my fingers, so I scrapped that idea.

Silver
There's a jquery typewriter effect.

http://www.mattboldt.com/demos/typed-js/

Which I might have a play about with after my success with transitions (fade outs/ins are, like, 3 lines of code).

Silver
I know I'm talking to myself here but the other alternative would be to forget the command (it leads to only a choice really) and just put links in that string. I like this idea actually.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums