0 votes
by (120 points)

I am trying to make a text that changes repeatedly when you mouse over it.  

Currently, I am using mouseover-replace to either



(mouseover-replace: "What")[(either:"Who", "When", "Where", "Why", "How", "What")]

But it only lets the reader change the text once....  then the text is stative.

Is there a way to do mouseover-replace repeatedly without having to refresh the page?

1 Answer

0 votes
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as answes can vary based on this information. Based on the syntax of your example I will assume you are using Harlowe, I will also assume you are using Harlowe v3.0.2 as that is the latest version at this time.

The (mouseover:) related macros are single use only so to reactivate the "mouse over" event monitoring you will need to call that macro again at the end of the code contained within the associated hook, and because you are replacing the target you will need to either change the target to be the same as the replacement text or use a named hook instead.

The following solution uses a child Passage named What Replacement to contain the code that will be executed within the (mouseover-replace:) macro's associated hook, it uses a (display:) macro to include the contents of the child passage as necessary, and it also replaces your original target of "What" with a named hook named what.

1. The What Replacement passage.

(either: "Who", "When", "Where", "Why", "How", "What")\
(mouseover-replace: ?what)[(display: "What Replacement")]

2. The Passage in which the replacable text appears in

(mouseover-replace: ?what)[(display: "What Replacement")]

Now when you view that passage you will see that the "What" text is randomly replaced any time the mouse cursor is over that area, you will also notice that because "mouse over" events are constently being sent that the text will change continuously as long as the mouse cursor is held over that area.

If you want the text to only change once per mouse over sequence then you will need wait until a "mouse out" event for that area has occured before reactivating the (mouseover-replace:) again. To do this replace the What Replacement child passage with the following which uses the (mouseout:) macro to cause the required delay.

(either: "Who", "When", "Where", "Why", "How", "What")\
(mouseout: ?what)[(mouseover-replace: ?what)[(display: "What Replacement")]]


by (120 points)
Wow!  Thank you.  I still need play with this a bit and see if I can understand how it works.  So new to this.  But so far so good!  And, yes, I am using Harlowe v3.0.2