GetInput = nothing

Hi, 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


There 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.


Hi 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")


When 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.


@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)
    }
  }
}

I 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 ().


Log in to post a reply.

Support

Forums