How to have a verb do multiple things? [SOLVED]

Hello! I am very very new to this (as in I downloaded this game late last night levels of new) So i'm sorry if this question is silly. I looked around on the forums but perhaps im not looking in the right places!

Anyway, I'm looking to have a character read a book but I can't figure out how to have "read book" bring up multiple phrases. I don't want them all coming up at once, but I have about 4 different passages written for the character to read.

Basically like read the book, then flip to another page and read again (if the player does so) and so on and so forth.

Again sorry if this is something thats been answered before or is sort of a dumb question. Thank you!


I'm also very new but I think I have a solution, using Script options called:

  • Set Variable or Attribute
  • Show Menu
  • Switch

This is usually for multiple choices, but you can use it with single choices.

If you know how to use Code View on the little Script Window, you can Copy & Paste the following in, and then turn off Code View on that Script Window to see how it looks in the Quest Interface.

continueBOOK = Split("Continue")
ShowMenu ("THIS IS CHAPTER 1 TEXT", continueBOOK, true) {
  switch (result) {
    case ("Continue") {
      continueBOOK = Split("Continue")
      ShowMenu ("THIS IS CHAPTER 2 TEXT", continueBOOK, true) {
        switch (result) {
          case ("Continue") {
            continueBOOK = Split("Continue")
            ShowMenu ("THIS IS CHAPTER 3 TEXT", continueBOOK, true) {
              switch (result) {
                case ("Continue") {
                  msg ("THIS IS CHAPTER 4 TEXT")
                }
              }
            }
          }
        }
      }
    }
  }
}

What is happening here is:

continueBOOK = Split("Continue")
is creating a variable and calling it continueBOOK, then filling that variable with Split options, in this case, only 'Continue'.

ShowMenu ("THIS IS CHAPTER 1 TEXT", continueBOOK, true) {
is giving the player a list of options, and it's getting that list (in this case only 'Continue') from the variable continueBOOK that we just made. (I dont know what the 'true' on the end means tbh)

switch (result) {
I think is just the game knowing how to treat the options?

case ("Continue") {
just means 'what happens when they choose the split option "Continue"'. for multi options you would have multiple case lines.

after that, the menu method just repeats itself, but using the next chapter's text for the Text of the 'ShowMenu' Menu. Im using the Menu's title to show the story instead of using a 'print message' option.

The last time, I do use a 'print message' option, because it's the last chapter and the player doesnt need a command to go do something else ^^


I should point out that this is a little more complex than it needs to be. The switch and case is just like putting if (result = "Continue") {, but it's more efficient than if when there are lots more options. But in this case, you already know what result is, because there's only one option. So you could just do:

msg ("THIS IS CHAPTER 1 TEXT")
ShowMenu ("", Split("Continue"), true) {
  msg ("THIS IS CHAPTER 2 TEXT")
  ShowMenu ("", Split("Continue"), true) {
    msg ("THIS IS CHAPTER 3 TEXT")
    ShowMenu ("", Split("Continue"), true) {
      msg ("THIS IS CHAPTER 4 TEXT")
    }
  }
}

(Not sure if you want to put the chapter text in the ShowMenu function, or print it first. The big difference is that putting in on the ShowMenu line will cause it to be a part of the menu, so it will be hidden at the end of the turn (so the book's content disappears from the screen as soon as the player clicks "Continue" or stops reading).

I wasn't sure what kind of interaction the original poster wanted.
This solution is a good idea if you want a "Continue" link, but you also want the player to be able to type another command and do something else.

If you want to force them to press continue, you would instead use:

msg ("THIS IS CHAPTER 1 TEXT")
wait {
  msg ("THIS IS CHAPTER 2 TEXT")
  wait {
    msg ("THIS IS CHAPTER 3 TEXT")
    wait {
      msg ("THIS IS CHAPTER 4 TEXT")
    }
  }
}

If you want the book to show a different page the second time the player uses the "read" verb, you would make it something like:

if (not HasInt (this, "chapter")) {
  this.chapter = 1
}
else {
  this.chapter = this.chapter % 4 + 1
}
switch (this.chapter) {
  case (1) {
    msg ("THIS IS CHAPTER 1 TEXT")
  }
  case (2) {
    msg ("THIS IS CHAPTER 2 TEXT")
  }
  case (3) {
    msg ("THIS IS CHAPTER 3 TEXT")
  }
  case (4) {
    msg ("THIS IS CHAPTER 4 TEXT")
  }
}

Or if you have 4 pages and you want to pick one at random each time you read the book:

switch (GetRandomInt(1,4)) {
  case (1) {
    msg ("THIS IS CHAPTER 1 TEXT")
  }
  case (2) {
    msg ("THIS IS CHAPTER 2 TEXT")
  }
  case (3) {
    msg ("THIS IS CHAPTER 3 TEXT")
  }
  case (4) {
    msg ("THIS IS CHAPTER 4 TEXT")
  }
}

(Or, if you have the verb's type as text rather than script, you can use the Text Processor's random function:

{random:THIS IS CHAPTER 1 TEXT:THIS IS CHAPTER 2 TEXT:THIS IS CHAPTER 3 TEXT:THIS IS CHAPTER 4 TEXT}

Yes!! Thank you to you both but mrangel that was exactly what I needed!! Thank you so much!!


I personally really like the way the Switch Menu Text method switches out the last chapter for the new one.

Is there a way to 'clear previous X lines' or something, for the

msg ("THIS IS CHAPTER 1 TEXT")
wait {
  msg ("THIS IS CHAPTER 2 TEXT")
  wait {

method?


Is there a way to 'clear previous X lines' or something

Before outputting text, use:

game.section_to_hide = StartNewOutputSection()

(where game.section_to_hide can be any object and attribute name that makes sense)

After outputting the text:

EndOutputSection (game.section_to_hide)

And when you want to make it disappear:

HideOutputSection (game.section_to_hide)

(ShowMenu uses the attribute game.menuoutputsection – so someone who doesn't like the way the menu hides answers could do something like:

ShowMenu ("What… is your favourite colour?", Split("lavender;pink;purple;mauve;burgundy"), true) {
  JS.eval("$(\"a[onclick^=\\\"ASLEvent('ShowMenuResponse'\\\"]\").removeAttr('onclick');")
  // code to handle answers here
}
game.menuoutputsection = ""

Which disables the hiding. (The JS.eval line disables all menu-response links in the output, because clicking one after Quest thinks you already responded to the menu would be a problem. I prefer to use a slightly more complex version, which hides all menu options apart from the one you chose… but that takes quite a bit more code)


Is there a way to 'clear previous X lines' or something

If you actually want to remove a number of lines, rather than a section you previously marked, you could use javascript to remove the last "line", although what it considers a line may be confusing at times. I'm removing <div>s, which normally correspond with each call to msg; but may be part of a line if you used OutputTextNoBr, and may miss anything that was printed using OutputTextRaw.

for (i, 1, number_of_lines) {
  JS.eval("$('#divOutput > div > div').last().remove();")
}
JS.eval("$('#divOutput').css("min-height: 0");

Or animating like HideOutputSection does:

for (i, 1, number_of_lines) {
  JS.eval("$('#divOutput > div > div:not(.removeline)').last().addClass('removeline');")
}
JS.eval("$('.removeline').hide(250, function () { $(this).remove(); }); $("#divOutput").animate({'min-height':0}, 260);")

It's normal to ask what you don't know, don't worry, if you have more questions write them down, because that's the only way to develop! So I prefer to write each chapter or new idea in a new row. I read https://freebooksummary.com/category/cats-cradle and it is easier and clearer for me to have each idea separately. The essence of the free book summary remains the same and is structured in this way. Also, when programming, I like to set Cats Cradl's work characteristics more organized.


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

Support

Forums