Script that changes page description or adds scripts depending on which page you came from

I'm making a gamebook. I want to know if there are any scripts like the following,

If: Player came from [page name], Then: ...

I'm pretty new to scripting, and sorry if I didn't explain it very well.

edit: Is it also possible to add other scripts instead of the page descriptions?


(in this post, I'm showing script in code view. If you prefer to use the GUI to enter scripts, you can paste it into code view and then switch back so it will show you what the script looks like)

In most cases, it's probably easier to use an attribute as part of your description.

For example, here's a part of the story where you're enjoying a picnic with some character. The player gets asked what they want to eat. On the page "eat sandwich", there's a description of what the sandwich is like, and a 'script' section which contains the line:

thanks.foodeaten = "sandwich"

On another page, maybe the player chooses to snack on cupcakes. There's a little banter and some stuff might happen, and the line:

thanks.foodeaten = "cakes"

Both of these pages have a link to a page named thanks where you say thankyou to the NPC, and leave. Its description includes the line:

“I had a great time," you say. “Thank you for the {thanks.foodeaten}, but I really need to go save the world.”

Most cases where you want to change a future page would be easier done by setting some variable on the previous page. If you visit more than one of these pages, it will use the most recently visited.

Note that you can call the attribute anything you want; thanks.lasteaten is just an example. The part before the dot must either be the exact name of a page (normally the page you're using it on), or game, or player. This makes it easier to keep track of them when the game gets more complex.

or

If you really want to find the last page visited, then you will need to modify the core scripts a little. On your first page, put a script like this:

game.lastpage = player.parent
player.changedparent => {
  game.lastpage = oldvalue
  DoPage (player.parent)
}

Then, a page which needs to change depending on where you came from can include a description like this:

You stride into a clearing. {if lastpage=slap john:You can still hear John yelling angrily after you.}

Note that you have to enter the name of the page exactly, including whether it's capitalised or not.

If neither of these methods works for you, could you provide a little more detail about your situation?


Okay, imagine there were 4 pages, all named Page1, Page2, Page3 and Page4. From Page1, you can go to Page2 and Page3. Both Page2 and Page3 leads to Page4. I want Page4 to change the page description (or better yet, add more scripts to it) depending on which page you came from. I could use the 'if player has seen page' script, but I really want these pages to be used multiple times.

Edit: Also, if there would happen to be a Page5 too, is it possible to have the changes that were applied to Page4 instead be applied to Page5 or any other page? Or do I just use flags for them?

Again, I am pretty new to quest. Started using it in april, using scripts since last month, and literally no coding experience. Sorry for the inconvenience, but thanks for the help.


You could create a string attribute to include in Page 4, as I suggested previously. Or you could set a flag when visiting each of those pages, and have your script choose what to do based on that.


OR... something simple and different...
Before you start:
game.p1=""
game.p2=""
game.p3=""
on page 1:
game.p1="So, you were on page 1, I guess everyone starts there."
on page 2:
game.p2="Then you went to page 2, half the people go there."
on page 3:
game.p3="Then you took the road to page 3, not everyone goes that way."
on page 4:
(room description)
msg (game.p1)
msg(game.p2)
msg(game.p3)
msg("So, did you like your trip?")

Altho, this will leave a blank line for the "path not taken"...


Okay, hopefully this will be the last question I have. Now imagine there were only 2 pages, Page1 and Page2. Page1 has about 3 links that lead to page2. Is it possible to have the page description and page scripts change depending on which link I used? Or am I just expecting too much from gamebook.

Anyways, thanks for all the help.


Page1 has about 3 links that lead to page2. Is it possible to have the page description and page scripts change depending on which link I used?

No. When the player clicks a link in gamebook mode, their browser sends the Quest backend a "command" which is simply the name of the page they're going to.

In fact, I think the default options menu can't contain two links that go to the same page.

The usual way to deal with this situation is to write 3 different copies of Page2, one for each of the options.
If this isn't practical, you could have 3 'dummy' pages, which the player can never visit them. Each of them just sets a flag or number, and then sends the player to the real Page2.

For example, one of them might have the script:

Page1.which_link = "Link 1"
MovePlayer (Page2)

Is it possible in text adventure type games?


In text adventures, you don't have pages and links. The closest thing would be rooms and exits; and there's no problem having multiple exits. In a text adventure, an exit can have a script that runs when you go through it, before (or instead of) reaching the room on the other side.


Okay, thanks for all the help.


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

Support

Forums