Light switch help.
ManMan
28 Sept 2016, 21:26I have a room, and the description of the room states that it's dark. I have a light switch object that can turn on or off. Whether it's on or off though, when look at room, it states it's dark. How can i change the look at room description depending on whether the light is on or off? Please help!
Niekitty
28 Sept 2016, 22:34The lightswitch system uses a couple of attributes, but mainly you are looking for a couple things for this.
If the room is set to be dark, it will have an attribute called "dark". the "room is initially dark" toggle sets the attribute to "True".
this is where the messy, codey stuff comes in. :)
- Lightswitch has to change the rooms dark attribute to "False".
- in the "After Switching On the Object" section for mister lightswitch, place a script line. if you are using the GUI instead of straight code, look for "Set a variable or attribute"
- You should get a line that says: Set variable [ ] = [expression] [ ]
- the variable will need the name of the Object/Room and the attribute to change, so that will be Room.dark
- for the expression, all you are setting it to is False
switching the lightswitch off will be the same thing, but setting the attribute to True.
turning the Dark to False will switch it to show the room description instead of the dark room description.
Be aware, the GUI gets VERY twitch about capitalization. you WILL have to capitalize the first letter of True and False, or it is very likely to get confused.
There are a few other ways to do this, but that's the simplest that I've cooked up. The Switch On and Off verbs that are created automatically should take care of checking to see if the switch is on or not already.
ManMan
29 Sept 2016, 00:47Thanks so much, you're a saint :)
XanMag
29 Sept 2016, 01:19I have several ways of creating light/dark rooms and each kind of serve a different purpose.
In my tutorial, I have these brief explanations to help users understand how they work. The first explanation of the room is this:
"So, I cheat a bit here. I have the switch, which will obviously turn on the lights. If you create object switch and tick the switchable option under features, you will have an option to run a script when object is turned on. In this script, I add a message to tell the player the light switch is flipped and I also make each object in the room visible. Then, in the turn off script I just do the opposite."
This is an excellent way to utilize light/dark rooms and still have other options available. Like seeing a light switch or seeing traces of things in the dark or for SEEING exits!
Another explanation is this:
"Not much to this.
The player is starting inside a cardboard box and must get out to continue.
- I created a room called 'unknown dark room'.
- In the look description, I gave the hint that you could feel the walls. The walls are ticked as a scenery object, which means they cannot be seen in the object panes but they can still be interacted with. Scenery objects can be added to give your game depth OR, in this case, scenery was used to kind of force the player to pay attention to key text in another look at message. Also, I don't feel it is necessary to draw the players attention to every wall, or floor, or cloud, or dirt path in the game, but it is nice to be able to look at them!
- I added 'feel' to the object walls (which I also added). 'Feel wall' would also be recognized by Quest because it matches the object name 'walls'. Any named object will do this.
- In this script, I chose to make an exit visible. You will need to name the exit from one room to the other to be able to make it visible. You can reverse this to make an exit invisible too.
- When you create an exit, go to the edit exit and simply untick the visible box and give it a name just above.
Exits in this case are no different than objects!"
This is good if you want to sort of trap a player in a room, but give hints within the dark room for them to solve certain puzzles to either get out of the room or to light the room up.
As far as I know, this is a tricky bit for the player and can be a bit unnerving for the player. It's VERY easy for the game creator though. Here is the explanation for that room:
"To use the built-in feature for light and dark rooms, you must have the "lightness and Darkness..." box ticked on the games tab.
- On the room object select the 'Light/Dark' tab.
- Tick 'room is initially dark' box.
- Add a room description here.
- Add a room description for the room description as normal as well (this will be for when the room is lit up).
- Whatever your event is that lights up the room (it could be carrying a torch, a set flag, the use of a switch, a magic word), simply add a 'make room light' script for that event! You can do the same for whenever you want to make a room dark!"
If the player wanders into a dark room without a light source, everything is made invisible except the room description. This can be a killer if left as is. Nothing is visible, even exits. In one of my games I have several dark rooms, but I combine them with a 'before entering room script'. In this script, I have an 'If' script that checks to see if the player has an illumination source in their inventory. If not, I script the player to immediately move out of the room (or not allow them to enter the room to begin with), and then I return them back to the lit room from whence they came.
There are lots of ways to handle this, but the different options certainly work better for different scenarios.
Let me know if you have questions. Good luck!

Anonynn
29 Sept 2016, 02:05You can also add some cool ambience by setting attributes. For example...
Lamp Object
Attribute
flag: boolean
When lamp is switched on, lamp.flag=True.
When lamp is switched off, lamp.flag=False.
Then in your text you can say...
{if lamp.flag=True:The light was shining brightly in the room.}{if lamp.flag=False:The room was dark with no signs of light.}
Just thought I would throw that in there!
Niekitty
29 Sept 2016, 21:46Gah, yes, I forgot about not being able to see the exits unless they're a weak lightsource by themselves. XD
Yesterday just makes me feel smarter and smarter.
headdesk
hegemonkhan
29 Sept 2016, 22:39the joys of programming... programmers like frustration... and being bald (from pulling our hair out)... and having a big red/black/purple bruise from hitting our heads on the desk... the joys of programming... troubleshooting... like more than 50% of programming... is just trouble shooting... lol.