Curious behaviour with JavaScript

The Pixie
I was messing around with JavaScript prompts (based on an example by Pertex), and discovered something rather odd. Here is the script:

    <start type="script">
question = "What is your name?"
default = "Anonymous"
request (RunScript, "jsinputbox;"+ question +";"+default + ";NameOutput")
on ready {
question = "How old are you?"
default = "0"
request (RunScript, "jsinputbox;"+ question +";"+default + ";AgeOutput")
}
</start>


What is strange is that the player is asked his age first, and then his name, despite the on ready command.

File:

Struggling to upload the JavaScripot file, so this is the content:

function jsinputbox(question, def, callback) {
var answer = prompt(question, def);
ASLEvent(callback, answer);
}

Alex
"on ready" fires when there are no outstanding ASL callbacks - things like "wait", "ask" etc. It doesn't know anything about what's happening in Javascript-land, so it will trigger immediately in your example.

If you want to fire some ASL after the Javascript, use ASLEvent (as you are currently doing) to ask the second question. Then there will only be one Javascript prompt at a time.

The Pixie
So why do they fire in reverse order?

Alex
I don't know, maybe the later one appears in front of the first one?

The Pixie
No, the first window does not appear until you dismiss the second one.

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

Support

Forums