Lights and switches library

levicki
Here is a simple and compact library for handling lights and switches which I have just written.

In order to use it, you have to do the following:

1. Add the Lights.aslx library to your game
2. Create object light which will inherit from light_source type.
3. Create object switch which will inherit from light_switch type.
4. On the object switch add the attribute source of type object and assign the object light to it.
5. On the object light add the attribute room of type object and assign the object room (where "room" is the one containing light) to it.

Features and limitations:

1. You cannot turn the lights on if the room is not dark.

If you want the lights to work, you need to call SetDark(room) or set it to an initial dark state from the editor.

2. You can have multiple light sources in the same room but each requires its own switch.

Reason for this is that it would be much more complicated to write code to deal with one switch that controls multiple lights (yes I was lazy).

3. You can have multiple light sources in the same room but only one can be active at a time.

Reason for this is the way how Quest CheckDarkness() function works -- one strong light source is enough to illuminate the room and there is no code in Quest to handle addition of weak lights and checking if they together make strong light. If you don't like it you can always ignore darkness status of the room but then why did you want lights in the first place?

4. You can have a switch in one room and light in another room.

This comes in handy when part of puzzle.

5. You can have more than one light switch in different locations controlling the same light.

For example, you can have a bedside switch for a central bedroom light, and one by the entrance. That way player could reach the light if they are in bed.

Final notes:

- If you have time keeping in your game and you want to make some rooms dark at night using a turn script, the proper thing to do is to use SetDark(room) and SetLight(room) for each room affected by global illumination (i.e. the one that has windows and is not underground).
- This library overrides default behavior of CheckDarkness() function -- keep that in mind if you notice any weird behavior with light sources in game.
- If you do not assign light to a switch or if you do not assign parent room to a light, you will get a runtime error message saying which object you forgot to assign something to.
- If you want to translate or otherwise change the messages, they are all in templates and dynamic templates at the beginning of the library code.


Code is free for non-commercial purposes provided that you mention me in your project as its author.

Criticism, comments, and suggestions are welcome.

UPDATE:

2013-03-24 - Version 1.1 - There is a new boolean attribute "disabled" for light switches so you can control whether they can be used or not without having to make code editable. Also, there is a new script attribute "disabled_message" for light switches which gets executed when the player tries to switch the disabled light on or off.




P.S. For those curious: the reason why light must "know" about its parent room is because otherwise you have to perform extensive search of light's parents and override even more Quest code to make things work. Quest by default doesn't "see" the light which is not a direct descendant of the room. For example, if you turn on the light which is on a table, CheckDarkness() won't change the darklevel attribute of the room, and the room will for all purposes and intents stay dark even though the light is on. This will probably be fixed in Quest 5.4 release so expect an update afterwards.

HegemonKhan
Another excellent library! thank you levicki! Now, I need to study it, hehe ;)
(the more code I can look at, the better, as I try to learn to code, and its logic~methods, more and more!)

levicki
HegemonKhan wrote:Another excellent library! thank you levicki!


You are welcome, let me know your thoughts if you actually end up using it.

HegemonKhan wrote:Now, I need to study it, hehe ;)


Good luck with that :D

Joking aside, if you really want to master Quest coding I suggest also looking at Quest library code -- a lot can be learned from there. That is what I did when I was writing this library. Your ability to write good code and make amazing things for a certain platform is directly proportional to your understanding of said platform.

HegemonKhan
you mean the quest engine's core (or core library anyways) code, right? Or, do you just mean anyone's created libraries' codes?

I've looked at the core library code, and it's really fascinating to see how Alex coding it to do all these things, though it's a bit beyond my level at this point, to even understand. I'm still just trying to learn a lot of the "basic" codings, like of your light switch library, spell~magic systems, combat systems, equipment (equiping) systems, (eventually) that journal making library, and etc people's libraries. I've never worked with any code ever before, so I'm really just still trying to learn, understand, and get used to doing all of these "simple" coding structures, logic, methods, and etc.

I am interested in taking some programming classes eventually, though I wished I had started on this as a kid, as it's so late for me now, so old, more tired, less energy, and more difficult to learn this new stuff now too, sighs. But I really like quest, as I'm able to slowly learn at least it's coding, laughs. Then, I can start making some games here, for people to play, hehe. I don't want to make bad games though, so that's why I'm trying to learn the programming side, so I can do cool stuff in my quest games. (I actually have more trouble with the GUI, as my brain does seem to be stronger with working with the code, for me). As I'm not too great of a story teller. I can write pretty well, but not that good at actual writing stories, lol. I don't have the art or other media abilities, so the programming ~ coding is my best bet of being able to improve upon it, and, at least, do this part of game making, eventually decently (hopefully), lol.

As I've been pretty good in math a science, and I'm very methodical, I get the general logic of thinking that is involved, but it is hard to translate that into how to actually code it, as I just don't know coding and its logic or way of doing things, and of in thinking of how to do the things via the ways the code can do it, when I don't know code very well, though I'm slowly learning.

But, the "if" and other type of structures~logic, I get pretty well, for the most part. I still have a bit of trouble of whether or not, I need to do a "check" on an object (or whatever).

levicki
Library has been updated to version 1.1.

This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums