Lightsources VS Darkness

TriangleGames
14 Feb 2013, 03:02
I have the character in a dark forest, at night. What I want to do, is require her to have a lightsource (a torch) in order to move safely around the forest and be able to "fully see" the objects around her. I am also planning on her coming back to these same areas after dawn (and some events that will seriously change the area), so I'm not sure what to do about the Dark room description vs the Default room description.

I have a couple of thoughts on how to deal with this, but they all seem suspiciously tedious, making me think there might be an easier way.
For instance, if the lightsource changes the room descriptions from Dark to Default, than I have to do something else to change those rooms once morning comes, like use an If...flag: morning script to define ALL their descriptions.
If I use a "fake" torch (i.e. not actually a lightsource) in a dark room, then I have to make all the objects and exits in the room become weak lightsources once the character gets the torch, to simulate the torch making them visible (or change their Visible attributes, I suppose).
I could also just "replace" all the rooms after dawn with a completely different series of similar rooms, but that feels like wasteful overkill, and plain bad programming.

Anyone have a suggestion on the best way to achieve going through
1. Dark, at night
2. Torchlight, at night
3. Daylight

homeeman
14 Feb 2013, 03:49
If I were in your position, I would probably set the "take" script for the torch (or the "use" script, however you have it) to make the player a strong light source when they take it (or use it). You could easily turn it off when they drop or... un-use it.
That, I believe, is as simple as setting the light source attribute to "True."

This, however, would necessitate an "if" statement for morning. Well, that's how I would do it, but there's more than one way to do anything.
If it was that much trouble (or if day and night are that different), you could make a different set of rooms for day and night.

HegemonKhan
14 Feb 2013, 04:28
Are you working with Pixe's clock library (dynamic~changing time of day) or are you just going to use flags of "morning~light" and "night~dark" and the darkness~lightsource stuff ???

if you using Pixie's clock library, you may be able to stick the code in their too, but you'd still have to set the if flags for the day~light and night~dark room descriptions.

TriangleGames
14 Feb 2013, 06:01
I thought about using the clock, but I really only need night and day, so it seemed like a lot of extra material for what should basically be "day" or "not day."

Pertex
14 Feb 2013, 08:40
I think I don't see the real problem at the moment, but I would do something like this:
1. set all rooms to dark
2. Add a scenery object to each of this dark rooms. The alias should always be the same but a common alias like 'light' or 'object'. The palyer should not be able to guess the right name.
3. When day or night changes, I would call a function like this, which would lighten the room

      
foreach (obj, AllObjects()) {
if (obj.alias="123lightobject123") {
SetObjectLightstrength (obj, "strong")
}
}

TriangleGames
15 Feb 2013, 02:08
That looks like an excellent way to handle the coming of dawn for multiple rooms, thanks.
The main complication I'm looking at, though, is determining the most efficient way to simulate a third level of darkness, such as "partial darkness" or "illuminated darkness." I want to distinguish between a room that is not dark and one that is dark but contains a lightsource. The point being that while carrying a torch at night let's you see objects and exits, it is not the same as daylight. I believe CheckDarkness(), as opposed to CheckDark(), will look to see whether a lightsource is present in a dark room. But if I use that in the room's Dark description script, it's never read, because the lightsource makes the system go to the Default description. I think I've figured out what I'm going to do, but I'll basically be faking darkness in most of the rooms, and therefore telling the player "you are not allowed to put down the torch, because then you'd notice that you don't actually need it anymore."

HegemonKhan
15 Feb 2013, 04:40
maybe, you should make some kind of function for what you want, then you need only to add (call on) the function name for~to the rooms' descriptions (or whatever else).

<function name="check_and_set_light_dark_levels">
if (room.dark = true) {
if (player.holding_torch and torch.switchedon = true) {
room.light_dark_level = weak_light
room.description = weak_light
}
else {
room.description = dark
}
}
else {
if (room.light = true) {
room.description = light
}
}


and you'd have to add in the:

if (room.description.light = true) {
msg (???)
}
if (room.description.dark = true) {
msg (???)
}
if (room.description.weak_light = true) {
msg (???)
}


as well, for what room description gets shown.

TriangleGames
15 Feb 2013, 20:30
OKAY, I finally realized what makes this simpler. When the player enters a room, the game uses CheckDarkness() to choose between the Dark or Default room description. Which means that if EITHER the room is not dark OR there is a lightsource, it displays the default room description, which totally makes sense for most purposes.
So all I have to do is set the default description to script and use if...ROOMNAME.dark = true to provide two separate descriptions,
because even though it's using the default description, the room's dark attribute has not actually been changed by the lightsource.

Thanks for the ideas, that really helped me wrap my head around this, and I will probably use a similar function to create dawn.