Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Making text dissapear or switch after doing something

edited May 2016 in Help! with 2.0
I'm pretty sure this was answered, but in a different way than I could understand to my knowledge, I did look for almost an hour though but, I have a part in my passages where you have a choice to eat bread, and I want it to say "There are crumbs on the plate" instead of "There is bread on the plate" after you eat the bread. Thanks in advanced! :D

Comments

  • You need to state which Story Format you are using when you ask a question, as answers can be different for each one. I am going to assume you are using Harlowe.

    You also didn't supply an example of the content of your passage, so I will assume that it looks something like the following:
    You see a plate on the table, there is bread on the plate.
    
    What do you want to do?
    (link: "Eat Bread")[]
    

    You can use a (replace: ) macro within the (link:) macro to achieve what you want. The (replace:) macro can be used in one of two ways:

    1. Pass the text you want to replace:
    You see a plate on the table, there is bread on the plate.
    
    What do you want to do?
    (link: "Eat Bread")[
    	(replace: "there is bread on the plate")[there are crumbs on the plate]
    ]
    
    ... this method will search the current passage for ALL occurrences of the indicated text and replace ALL of them.

    2. Use a named hook to mark the text you want replaced:
    You see a plate on the table, |bread>[there is bread on the plate].
    
    What do you want to do?
    (link: "Eat Bread")[
    	(replace: ?bread)[there are crumbs on the plate]
    ]
    
  • Thank you, I'm new to the post and it was 1 am, I was tired. This helped a lot.
  • To follow up on this question, which is similar to mine--what if I have two options, but I only want the player to be able to choose one? So for example, there is bread and water on the table. But if you choose to eat the bread, you lose the chance to drink the water, and vice versa.

    Say I start with something like this:
    You see a plate and a glass on the table, |bread>[there is bread on the plate] and |water>[water in the glass]
    
    What do you want to do?
    (link: "Eat Bread")[
    	(replace: ?bread)[there are crumbs on the plate]
            (replace: ?water)[the undrinkable water taunts you]
    ]
    (link: "Drink Water")[
            (replace: ?water)[only drips remain in the glass]
            (replace: ?bread)[the bread is untouchable]
    ]
    

    This works as far as it goes but what I'd like to have happen is that the second link (whichever link the player doesn't click) also disappears, or becomes unclickable. Is that possible? Could I add something to this example to make that happen?

    I am using Harlowe and Twine 2.
  • hkfto wrote: »
    what if I have two options, but I only want the player to be able to choose one?
    You can use the same named hook / (replace:) macro technique to achieve what you want.

    The following wraps the links within an options named hook and replaces them with styled text.
    You see a plate and a glass on the table, |bread>[there is bread on the plate] and |water>[water in the glass]
    
    What do you want to do?
    |options>[(link: "Eat Bread")[
    	(replace: ?bread)[there are crumbs on the plate]
    	(replace: ?water)[the undrinkable water taunts you]
    	(replace: ?options)[<u>Eat Bread</u>]
    ]
    (link: "Drink Water")[
    	(replace: ?water)[only drips remain in the glass]
    	(replace: ?bread)[the bread is untouchable]
    	(replace: ?options)[<u>Drink Water</u>]
    ]
    ]
    

    note: You are indenting your code using space characters, you may find it quicker/easier to use tab characters instead (less typing).
  • Ah, that's terrific! Thank you, I'm going to give that a try. And yes, I used spaces instead of tab because when I pressed tab my cursor jumped to the post button. Just wanted things to look tidy.
  • hkfto wrote: »
    I used spaces instead of tab because when I pressed tab my cursor jumped to the post button.
    That is an issue with the comment field.

    One way to format code examples using tabs is to write and format it within the hosted Twine Passage Editor. *smile* Or a Text Editor if you have one. (Notepad?)
  • How do I make it so it stays saying "The plate only has crumbs", because if you go to the previous passage then go back, it just restarts.
  • Jaineer wrote: »
    if you go to the previous passage then go back, it just restarts.
    If you are using the Undo link to return to the previous passage then that is meant to happen. If you are using a link that moves the Reader forward to previous passage then you will need to use a variable to track that the Reader ate the bread.

    1. Add the following to your startup tagged special passage, it uses the (set:) macro to create a $ate_bread variable and defaults it to false.
    (set: $ate_bread to false)
    

    2. Now change the Eat Bread related passage to use an (if:) macro and an (else:) macro to show different text depending on the current value of $ate_bread variable.
    (if: $ate_bread)[You see a plate on the table, there are crumbs on the plate]
    (else:)[You see a plate on the table, |bread>[there is bread on the plate].
    
    What do you want to do?
    (link: "Eat Bread")[
    	(set: $ate_bread to true)
    	(replace: ?bread)[there are crumbs on the plate]
    ]]
    
    [[Next Passage]]
    
  • If I want the link to move me to the next passage, how would I do that?
  • I suggest reading through the Harlowe Manual, especially the Table of Contents which is the scrollable list of links on left side of the page.

    If you do this you will see a (go-to: ) macro listed within the links section of the ToC, use one of these to move to another passage.
Sign In or Register to comment.