GetInput = nothing
![](https://i.imgur.com/kGqRjqnb.jpg)
StokeBunnies
12 Feb 2024, 09:40Hi, I'm writing a simple quiz, and want to give players a 30sec time limit. When the time is up, move them back. I have a clock ticking sound which lasts 30sec, but struggling to work out how to write If GetInput = Nothing and Sound stopped then (whatever).
I've had a look round the forum, but can't see anything that fits
picture ("Pic01.jpg")
msg ("Which UK city is this? ")
play sound ("countdown30.mp3", false, false)
GetInput() {
if (result = "London" or result = "london" ) {
msg ("Well done, now try the next one.")
MovePlayer (Pic02)
stop sound
}
else if (result <> "London" or result <> "london") {
MovePlayer (Start)
stop sound
}
else play sound ("crowd-groan.mp3", false, false){
}
}
Which doesn't work. Really grateful of any help.
Chris
mrangel
12 Feb 2024, 11:23There is SetTimeout function; but I'm not sure if it works correctly with GetInput.
I'd probably do something like:
picture ("Pic01.jpg")
msg ("Which UK city is this? ")
play sound ("countdown30.mp3", false, false)
JS.eval("window.currentQuestionTimer = setTimeout(function() {sendCommand('TIMEOUT')}, 30000);")
GetInput() {
JS.eval("clearTimeout (window.currentQuestionTimer);")
stop sound
switch (result) {
case ("London", "london") {
msg ("Well done, now try the next one.")
MovePlayer (Pic02)
}
case ("TIMEOUT") {
msg ("Sorry, you're out of time!")
}
default {
msg ("Nope, that's not the right answer")
MovePlayer (Start)
}
}
}
This sets a piece of javascript running which will wait 30000 milliseconds (30 seconds) and then submit "TIMEOUT" as if the player typed it. So you can just check for that response like any other.
In this case, we cancel the timer and stop the sound before dealing with the result, because we want that to happen in any case.
![](https://i.imgur.com/kGqRjqnb.jpg)
StokeBunnies
12 Feb 2024, 13:43Hi mrangel,
Thanks for replying.
I now have an error
Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'script' to element 'Pic01': Missing '}'
I did try openscript. picture ("Pic01.jpg")
![](https://i.imgur.com/Xvt8zzBb.png)
daeun
13 Feb 2024, 23:17When I covert to non-code view form of mrangel's solution, I get
picture ("Pic01.jpg")
msg ("Which UK city is this? ")
play sound ("countdown30.mp3", false, false)
JS.eval ("window.currentQuestionTimer = setTimeout(function() {sendCommand('TIMEOUT')}, 30000);")
GetInput {
JS.eval ("clearTimeout (window.currentQuestionTimer);") {
stop sound
}
Meaning that the quest deletes away the code inside of GetInput, causing an error.
![](https://i.imgur.com/Xvt8zzBb.png)
daeun
13 Feb 2024, 23:57@StokeBunnies, maybe you can try this and tell us what happens?
From https://docs.textadventures.co.uk/quest/functions/getinput.html
https://docs.textadventures.co.uk/quest/scripts/get_input.html
It says GetInput() is changed to get input {script}
picture ("Pic01.jpg")
msg ("Which UK city is this? ")
play sound ("countdown30.mp3", false, false)
JS.eval("window.currentQuestionTimer = setTimeout(function() {sendCommand('TIMEOUT')}, 30000);")
get input {
JS.eval("clearTimeout (window.currentQuestionTimer);")
stop sound
switch (result) {
case ("London", "london") {
msg ("Well done, now try the next one.")
MovePlayer (Pic02)
}
case ("TIMEOUT") {
msg ("Sorry, you're out of time!")
}
default {
msg ("Nope, that's not the right answer")
MovePlayer (Start)
}
}
}
mrangel
14 Feb 2024, 07:54I now have an error
Sorry about that. I missed out the ()
after GetInput. I've now edited the script posted above.
Although, as daeun says, it is recommended to use get input
instead of GetInput ()
.