NPC Conversation

Hello, I am working on my first game and running into an issue I have yet to resolve. I would like for my player to have a discussion with Christian Doppler in which they are making observations about light waves. When the player makes a correct observation, Doppler asks another question. (This piece I am okay with.) When the player makes an incorrect observation, Doppler asks them to look more closely and asks the question again. I cannot seem to get an incorrect answer to loop back to the previous question, and I am not sure if I am missing something simple or if there is a more elegant way to approach these types of conversation. Here is the code. Thank you in advance for your assistance in this matter.

      <inherit name="editor_object" />
      <inherit name="namedmale" />
      <look type="script">
        picture ("Christian_Doppler.jpg")
      </look>
      <speak type="script">
        Ask ("Hello!  Would you like to help me study the way light and sound waves change as an object moves?") {
          if (true) {
            msg ("Great!  Let's look at this simulation.")
            DisplayHttpLink ("Simulation", "http://zonalandeducation.com/mstm/physics/waves/dopplerEffect/dopplerEffect.html", false)
            msg ("Mute (uncheck) the Snare drum sound. Try snapping your fingers every time a sound wave is produced. For now, let’s call this the frequency of waves emitted by the source.")
            msg ("Is the frequency of waves emitted by the source constant, or does it change as the source moves?  In other words, does the way you snap your fingers get faster, slower, or it is constant as the source moves along the screen?")
            menulist = NewStringList()
            list add (menulist, "slower")
            list add (menulist, "faster")
            list add (menulist, "constant")
            ShowMenu ("What do you think?", menulist, false) {
              if (result="slower") {
                msg ("Are you sure.  Take another look, and make sure your sound is muted.")
                ShowMenu ("What do you think?", menulist, false) {switch}
              }
              else if (result="faster") {
                msg ("Are you sure.  Take another look, and make sure your sound is muted.")
              }
              else if (result="constant") {
                msg ("Great! So what you are saying is that the waves emitted from the source have a constant frequency.")
              }
            }
          }
          else if (false) {
            msg ("Oh. Okay.  I'll keep working then.  If you have any questions about waves, you know where to find me!")
          }
        }```

As an alternative to the above method, I have been trying a method where there is a "conversationcounter" attribute for the NPC and the user. Not sure if this will help or over complicate the situation.

      <inherit name="editor_object" />
      <inherit name="namedmale" />
      <look type="script">
        picture ("Christian_Doppler.jpg")
      </look>
      <conversationcounter type="int">0</conversationcounter>
      <speak type="script">
        Ask ("Hello!  Would you like to help me study the way light and sound waves change as an object moves?") {
          if (false) {
            msg (".Oh.  Okay.  Well, if you would like to learn more about waves, you know where to find me.  I had better get back to my research!")
          }
          else if (true) {
            msg ("Great!  Let's look at this simulation")
            DisplayHttpLink ("Simulation", "http://zonalandeducation.com/mstm/physics/waves/dopplerEffect/dopplerEffect.html", false)
            msg ("Mute (uncheck) the Snare drum sound. Try snapping your fingers every time a sound wave is produced. For now, let’s call this the frequency of waves emitted by the source.")
            msg ("Is the frequency of waves emitted by the source constant, or does it change as the source moves?  In other words, does the way you snap your fingers get faster, slower, or it is constant as the source moves along the screen?")
            question1 = NewStringList()
            list add (question1, "faster")
            list add (question1, "slower")
            list add (question1, "constant")
            ShowMenu ("What do you think?", question1, false) {
              if (result="faster") {
                msg ("Are you sure?  Make sure you have muted the sound and try again.")
              }
              else if (result="slower") {
                msg ("Are you sure?  Make sure you have muted the sound and try again.")
              }
              else if (result = "constant") {
                Christian Doppler2.conversationcounter = Christian Doppler2.conversationcounter + 1
                msg ("Great! So what you are saying is that the waves emitted from the source have a constant frequency.")
              }
              if (Christian Doppler2.conversationcounter = 1) {
                msg ("Next Question")
              }
              else if (Christian Doppler2.conversationcounter = 0) {
              }
            }
          }
        }

Thanks!


The ask scipt command sets a variable called result, so should be used:

Ask ("Hello!  Would you like to help me study the way light and sound waves change as an object moves?") {
          if (not result) {
            msg (".Oh.  Okay.  Well, if you would like to learn more about waves, you know where to find me.  I had better get back to my research!")
          }
          else {
            ...

This will never happen:

          if (false) {
            msg (".Oh.  Okay.  Well, if you would like to learn more about waves, you know where to find me.  I had better get back to my research!")

To get the wrong answer to loop back, you will need to do all this in a function, and then call the function from within itself (called recursion). A simpler alternative might be to just allow the player to talk to Doppler again.


There are going to be a series of questions, so I guess recursive functions are my only option.


unfortunately, there's only (tail) recursion and/or using the 'while' Function for looping, but there's also the issue/crash/error that you got to deal with (you got to be much more creative with your scripting design) of doing looping while doing such functions that are waiting for (typed-in and/or maybe hyperlink/button presses) inputs and/or use a popup menu window for input selection ('get input','show menu', 'ask', etc), as only one of these can be active at a time, and the looping happens faster than the human can respond, thus creating two of them at the same time, and thus the error/crash. The tail recursion works pretty well, though if you can use 'while' instead of doing tail recursion, that's probably better/more-efficient/less-overhead, though I've no idea how the 'while' Function works compared to tail recursion in the number of operations/processes it's doing and/or how much overhead (activation record / frame) is involved with 'while' vs the 'tail' recursion.

there's also (list/string) iteration looping, but it's not the same thing as the 'looping' looping that we're talking about for your topic.


we do have some advanced dialogue/conversation code/design/library available by Pixie/Jay(jaynabonne), if you're interested.

(let me know if you need help finding them)


also, maybe some of this can be of help to you as well (if at least for maybe ideas, anyways):

(my brain wasn't working, and I didn't realize to consolidate my redundent functions into a single function using parameters, at the time, so ignore the bad/poor quality of it):

http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game

ask if you got any questions about anything or need help with anything


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

Support

Forums