Curious behaviour with JavaScript
The Pixie
30 Nov 2012, 08:14I was messing around with JavaScript prompts (based on an example by Pertex), and discovered something rather odd. Here is the script:
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:
<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
30 Nov 2012, 09:11"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.
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
30 Nov 2012, 10:52So why do they fire in reverse order?
Alex
30 Nov 2012, 12:40I don't know, maybe the later one appears in front of the first one?
The Pixie
30 Nov 2012, 12:47No, the first window does not appear until you dismiss the second one.