Howdy, Stranger!

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

Hide and show a text

Hi everybody!
I am using Twine 2 and Harlowe.
I was trying to do the following. I want to click on a sentence to show its meaning and after X seconds make the text disappear.
I did the following but after the meaning disappears I would like to be able to click it again but it is not possible.
Do you know how can I do that?
{
(set: $look to "This is the meaning")
(set: $clook to (text-style: "bold"))

}

<b>FIRST TRY: </b>
When you click on the sentence the meaning will appear for 5 seconds and then it will go away, but with this method you cannot click again and show the meaning:

[$clook[Click here to see the meaning.]]<meaning2|
(click: ?meaning2)[$look (live:5000ms)[(if: $look ="This is the meaning")(replace: $look)[ ]]]




Another approach I wanted to do was clicking the sentence and make the meaning appear and then click it again and make it disappear.
This code just makes the text appear
{
(set: $look to "This is the meaning")
(set: $clook to (text-style: "bold"))

}

[$clook[Click here to see the meaning.]]<meaning2|
(click: ?meaning2)[$look]


I know how to do that with javascript using the hide() and show() functions but I would like to learn how to do it in Harlowe.
Thank you!

Could you help me with any of these two approaches?

Thank you!

Comments

  • beafus wrote: »
    Hi everybody!
    I am using Twine 2 and Harlowe.
    I was trying to do the following. I want to click on a sentence to show its meaning and after X seconds make the text disappear.

    You can try using the (live:) macro. For example:
    (set: $clook to (text-style: "bold"))
    (set: $look to "This is the meaning")
    
    [$clook[Click here to see the meaning.]]<meaning1|
    (click: ?meaning1)[(live:1s)[(set:$pause to it +1)(if:$pause <7)[$look](elseif:$pause >7)[(set:$pause to 0)(stop:)]]]
    

    (NOTE: Always remember to include a (stop:) macro once the final hook is called so that it doesn't keep refreshing that hook.)

    I did the following but after the meaning disappears I would like to be able to click it again but it is not possible.
    Do you know how can I do that?

    The hooks are only useful one time, you can't keep using them unless you use another passage and then come back to the original one. (I also wanted to use hooks multiple times, because it would make things so much easier. but hey, we can't get everything we want!)

    Here's what I came up with for having text appear and disappear and then clicking again for it to repeat the process. It uses 3 passages:

    In your first passage:
    (set: $clook to (text-style: "bold"))
    (set: $look to "This is the meaning")
    
    (display:"MultipleClicksPassage01")
    

    Then create a passage called, "MultipleClicksPassage01" and put:
    [$clook[Click here to see the meaning.]]<multipleClicks01|
    (click: ?multipleClicks01)[(live:1s)[(set:$pause to it +1)(if:$pause <7)[$look](elseif:$pause >6)[(stop:)(set:$pause to 0)(replace:?multipleClicks01)[(display:"MultipleClicksPassage02")](stop:)]]]
    

    Then create a passage called, "MultipleClicksPassage02" and put:
    [$clook[Click here to see the meaning.]]<multipleClicks02|
    (click: ?multipleClicks02)[(live:1s)[(set:$pause to it +1)(if:$pause <7)[$look](elseif:$pause >6)[(stop:)(set:$pause to 0)(replace:?multipleClicks02)[(display:"MultipleClicksPassage01")]]]]
    

    Another approach I wanted to do was clicking the sentence and make the meaning appear and then click it again and make it disappear.
    This code just makes the text appear

    Here are two ways of doing this.

    The first one is without refreshing the First Passage:

    In your First Passage put:
    (set: $clook to (text-style: "bold"))
    (set: $look to "This is the meaning")
    
    (display:"MeaningPassage01")
    

    Then create a passage called, "MeaningPassage01" and put:
    {
    [$clook[Click here to see the meaning.]]<meaningLink1|
    (click-replace: ?meaningLink1)[(display:"MeaningPassage02")]
    }
    

    Then create another passage called, "MeaningPassage02" and put:
    [$clook[Click here to hide the meaning.]]<meaningLink2|
    [$look]<meaningMessage|
    {
    (click: ?meaningLink2)[(replace:?meaningMessage)[](replace:?meaningLink2)[(display:"MeaningPassage01")]]
    

    And here is a method that refreshes the First Passage:

    In your First Passage put:
    (set: $clook to (text-style: "bold"))
    (set: $look to "This is the meaning")
    
    [$clook[Click here to see the meaning.]]<meaning2|
    (click-replace: ?meaning2)[(display:"Next Passage")]
    

    Then create another passage called, "Next Passage" and put:
    [$clook[Click here to hide the meaning.]]<meaning3|
    This is the meaning
    (click: ?meaning3)[(goto:"First Passage")]
    

    All these examples can be found in the attached HTML file which you play by clicking on it, and can also save on your computer and import to Twine 2 to see the code.

    I hope this helps.
  • A few comments on the examples I gave.

    Example number 2 (Appearing and Disappearing text multiple clicks) is a bit buggy. After about four clicks it starts acting up (at least on Chrome). It must be due to the (live:) macro and how it all works, but since I know almost nothing about these things, I can't tell you why it behaves that way.

    Example number 3 (Clicking on and off without refreshing the current passage) is probably the best example. It works smoothly, and the benefit of not refreshing the current passage is if you have any (set:) macros, etc. in a passage and you don't want them to keep resetting.
  • edited June 2015
    Thank you very much @feliwebwork !!! I also think the best one is the example number 3.
    I really appreciate your help!
  • Both of your questions are similar to @feliwebwork question about "Replacing Text Back and Forth without Refreshing passage" and my response should work as is for your second question and only needs to be changes slightly for your first.

    The following handles your first question, it consists of three parts:
    1. Indicate where to show the link:
    {
    (set: $look to "This is the meaning")
    (set: $clook to (text-style: "bold"))
    
    }
    
    <b>FIRST TRY: </b>
    When you click on the sentence the meaning will appear for 5 seconds and then it will go away, but with this method you cannot click again and show the meaning:
    
    |meaning2>[(display: "Meaning2-Hidden")]
    
    2. A Passage containing what to show when the meaning is hidden (named Meaning2-Hidden)
    |opt>[$clook[Click here to see the meaning.]]
    (click: ?opt)[(replace: ?meaning2)[(display: "Meaning2")]]
    
    3. A Passage containing the meaning to be displayed when the link is clicked (named Meaning2)
    $look
    (live:5s)[
    	(replace: ?meaning2)[(display: "Meaning2-Hidden")]
    	(stop:)
    ]
    
    note: A (live:) macro will keep doing whatever you asked it to do until you either manually (stop:) it or until the the section it is attached to (ie. Passage, hook) is removed from the DOM.
  • greyelf wrote: »
    Both of your questions are similar to @feliwebwork question about "Replacing Text Back and Forth without Refreshing passage" and my response should work as is for your second question and only needs to be changes slightly for your first.

    Indeed. Tis' how I'm learnin! thanks @greyelf!!

  • edited June 2015
    Thank you both!!
    @greyelf @feliwebwork
Sign In or Register to comment.