Multiple Choice Trivia Question Help

Pigbeetle
01 Nov 2022, 17:48

To start with, hi all! I'm not entirely new, I'm returning to Quest after a few years with a renewed interest in writing text games (why write a book when I can turn it into a nifty little game instead?). I also have logic practice making small games in GBStudio as well.

And to preface, up to this point I've searched for most of the things I've needed help with on the forums (thank you so much everybody in the past for having the same problems as me), but I've reached an impasse with this one - or I'm so tired I've overlooked it.

I'm trying to write a trivia question with a chooseable multiple choice answer that affects a stat if you get it right (a stat I've not programmed yet, I just want to get the question running right first), and I found this post that helped a lot, but I've run into some errors with it.

https://textadventures.co.uk/forum/quest/topic/q_k0nxiemeqqgoiz2vfn3g/multiple-choice-quiz

My code, which runs when you "look at banjo" for the first time, looks like this:

<function name = "mq1_banjo">
show menu ("What is the standard tuning of a 5-string banjo?", split ("E A D G B E;D G B A B;G D G B D;A B C D E", ";"), false) {
  // quest hidden from you, does this for you: result = YOUR_SELECTED_MENU_CHOICE
  // (also for the 'get input' Script/Function, quest does the same: result = YOUR_TYPED_IN_INPUT)
  if (result = "G D G B D") {
    msg ("A finely tuned, and well taken care of instrument.")
    msg ("Skill up!")
    wait {
      ClearScreen
    }
  }
  else {
    msg ("Hmm, that doesn't sound quite right. Try again.")
    wait {
      mq1_banjo
    }
  }
}
</function>

I've copied this directly from the post and just changed the outputs, and fixed where some quotation marks were in the wrong places, but I'm getting an error. When I "look at banjo" in the game, this happens

> look at banjo
Error running script: Invalid variable name '<function___SPACE___name' in '<function___SPACE___name = "mq1_banjo">'

The program is taking it upon itself to change "function name" to "function___SPACE___name", and as someone who's unfamiliar with this part of programming, I'm just not sure where to go from here with it.

Thank you in advance for any direction!


Pigbeetle
01 Nov 2022, 21:31

In case anybody else ever searches for exactly this, I figured it out. You want to use ShowMenu () with switch results.
This makes it so that the options appear in the text rather than a pop-up menu, which was preferred for me, as well as makes the options in said list clickable.
The code, from an untuned banjo to a tuned one, achieved by answering a trivia question correctly:

msg ("This isn't your room, but this is your banjo.")
if (Banjo.tuned = false) {
  Ask ("Spend a moment tuning it?") {
    if (result=true) {
      tuningtrivia = Split("E A D G B;D G B A B;G D G B D;A B C D E", ";")
      PrintCentered ("Trivia!")
      ShowMenu ("What is the standard tuning of a 5-string banjo?", tuningtrivia, false) {
        switch (result) {
          case ("G D G B D") {
            set (Banjo, "tuned", true)
            msg ("A finely tuned, well taken care of instrument.")
          }
          case ("E A D G B", "D G B A B", "A B C D E") {
            msg ("Hmm, that doesn't sound right.")
          }
        }
      }
    }
    else {
      if (result= false) {
        msg ("Very well. You leave it be for now.")
      }
    }
  }
}
else if (Banjo.tuned = true) {
  msg ("It's been tuned, and you can tell it's loved and taken care of properly.")
}