Howdy, Stranger!

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

making a light swtich

Hi,
I'm trying to make a room with a light switch. If the light is off, the description says "it's dark and you can feel a switch". If you click the switch, I want to say "the light comes on" and replace the description with one that now reveals a door. Conversely, if the room is entered when the light is on, you can see the door and if you click the switch, I want to say "it goes dark" and replace the description with the words for the dark room.
I've tried using named hooks and (click:) macros and it works up to a point, but once a click link is activated, it can't be clicked again - or at least I've not managed to do it!
In the code sample below, the $StoreLampON variable is initialised in the preceding room (kitchen). Clicking the switch link works to turn the light on (or off) on first entering the room and the description changes. I just can't use the switch again unless I exit and re-enter the room.

{(set: $DarkWords to "It's pitch dark in here, but you can feel a [switch]<lightswitch| on the wall.")
(set: $LightWords to "There is a [switch]<lightswitch| on the wall. You see a [[door->TheCellar]] in the far wall ")
(if: $StoreLampON)[(set: $PassDesc to $LightWords)]
          (else:)[(set: $PassDesc to $DarkWords )]
}
#####In the storeroom
The door to the [[kitchen->Kitchen]] is behind you. [$PassDesc]<PassText|

(click: ?lightswitch)[
(set: $StoreLampON to not $StoreLampON)
(if: $StoreLampON)[The room is flooded with light.(replace: ?PassText)[$LightWords]]
          (else:)[The light goes off.            (replace: ?PassText)[$DarkWords ]]
]

The closest I've got to a perpetually active switch is to have two room descriptions in separate passages, one for dark, one for light, and a switch link to take you to the "other" room.  It seems a bit messy to do it this way so I'm hoping there's a way to make links active when they are replaced in a live passage.

Apologies if this has been raised elsewhere - I looked through 6 pages of topics and couldn't find anything suitable!

Gordon

Comments

  • Sorry for such a late reply - it took a while to figure this out:

    Of course you can't reactivate links without revisiting the passage. But you can reactivate them by just - revisiting the passage from the same passage. Figuratively speaking you are entering the room again. In this bit of code, I named the passage Light.
    (if: $init is 0)[(set: $init to 1)(set: $state to "on")]

    The light switch is [$state]<switch|

    (click: ?switch)[(if: $state is "on")[(set: $state to "off")](else:)[(set: $state to "on")](goto: "Light")]
    The bit at the beginning is checking if the room has been visited before and setting up the state of the light switch, you could also use:
    (if: (history:) contains "Light")[blah...]
    Or just set up the light switch in a previous passage. Then the rest is just toggling the state of the switch and bouncing the player back into the same passage when they click the light switch. This reactivates all the links. If you don't want all the links reactivated then you will need to set up some variables to track what has been clicked before.
  • no need to apologise for a late reply - the fact that I got a reply at all is nice, and the fact that the suggested approach works is even better  :)  Whilst I'd like there to be a type of link that was reactivated after clicking it (just like a button),  revisiting the passage via a goto does the same thing, and when combined with a (live:2s) macro, I can say "the light goes off" and give the player time to read it before the passage is refreshed. The only problem is the time it takes for the room to re-render, but it's no big deal.

    thanks again.

    Gordon
Sign In or Register to comment.