Making a basic 'brass lantern' that

shadowphile
As of Version 5.4.1 you still can't light up a room by carrying a lamp, you have to drop it on the floor first. (?)

If you have a need for a portable light-source in your inventory that lights up any room you visit, then do this:
Enable the core libraries in the object list on the left. (bottom left corner, click 'Filter' and enable 'Show Library Elements'

Right click on the Function list header and select 'Add Function', call it 'ScopeInventoryLightsources'.
Paste this in:
result = ScopeInventory()
lightobjects = NewObjectList()
foreach (obj, result) {
if (GetBoolean(obj, "lightsource") and GetString(obj, "lightstrength") = "strong") {
list add (lightobjects, obj)
}
}
return (lightobjects)

At the top set the Return Type to 'Object List'

Then find the existing function 'CheckDarkness', make a copy, and insert text as shown here:

First section of original code:
roomCheckDarkness = true
if (GetBoolean(game.pov.parent, "dark")) {
if (ListCount(ScopeVisibleLightsource("strong")) > 0) {
roomCheckDarkness = false
}


New code to insert:
  if (ListCount(ScopeInventoryLightsources()) > 0) {
roomCheckDarkness = false
}


Last section of original code:
}
game.pov.parent.darklevel = roomCheckDarkness
return (roomCheckDarkness)


Now when the flashlight object is in your inventory and switched on, it will light up any room you visit. As expected, the flashlight still won't light up the room if you have it contained inside something else in your inventory, unless that something else is a transparent container. All pretty cool!
------------------------------------------------------------------------------------------------------------------------------------

Here are some more trivial scripts to help make that flashlight more practical, I offer two different approaches:

First style:
Pros: Will light up a room whether held in inventory or dropped on the floor.
Cons: If 'switched off' in a dark room and dropped, you will not be able to see it or pick it back up, possibly leaving you stuck in a dark room.

Second style:
Pros: Will light up a room whether held in inventory or dropped on the floor.
Cons: If 'switched off' in a dark room, you can still see it either in your inventory or dropped on the floor. If you want your switched-off flashlight to NOT be visible on the floor of a dark room, you must use the First style above.

I offer both styles with a command that reprints the room description again in case you want to describe the room after the light level changes. If you don't like it, just delete the 'ShowRoomDescription' command.

(paste these in while it's in code-view)
First-style code:
Put this chunk in the flashlight's 'After Switching On the Object' script:
flashlight.lightstrength = "strong"
flashlight.lightsource = True
ShowRoomDescription


Put this chunk in the flashlight's 'After Switching Off the Object' script:
flashlight.lightsource = False
ShowRoomDescription


Second-style code:
Put this chunk in the flashlight's 'After Switching On the Object' script:
flashlight.lightstrength = "strong"
flashlight.lightsource = True
ShowRoomDescription


Put this chunk in the flashlight's 'After Switching Off the Object' script:
flashlight.lightstrength = "weak"
flashlight.lightsource = True
ShowRoomDescription



Hope this helps others. I spent several days coding spaghetti before I figured out how the Quest execution is structured.
If any gurus out there see a big loophole or think this creates problems elsewhere, by all means shout out.
good luck

Pertex
Hi shadowphile,
isn't it an easier solution to add the line
result = ListCombine(result, ScopeReachableInventory())
to the function ScopeVisibleLightsource?



<function name="ScopeVisibleLightsource" type="objectlist" parameters="lightstrength">
result = ScopeVisibleNotHeld()
result = ListCombine(result, ScopeReachableInventory()) <---add this line
lightobjects = NewObjectList()
foreach (obj, result) {

shadowphile
DOH!, I suppose you are right, since you know the code way better than I do.
Frankly, I posted it because it was very simple compared to the horrid hoops I was jumping through before that, trying to manipulate the Dark variable for rooms. The hardest thing is trying to decode the structure of the library calls.
In this case I didn't understand that the descriptions are steered with an on-the-fly filtered set of lightsources; but rather I thought originally that the motion and changing of lightsources iteratively changed a single variable used to steer the description, in this case the Dark attribute. Was I wrong!

I didn't explore the Reachables and Accessibles because, well, it was hard to decode what those actually filter for. Guess my intuition about whether something is reachable did not match whether it was also visible.
Care to elaborate about the difference between Reachable, Accessible, and Visible? (and while we are at it, what 'darklevel' is used for..)

And what do I do about my 'solution', since it's already obsolete? Don't want to leave a poor chunk of code lying around to waste somebody else's time. Next time I'll post my solution in the regular forum for feedback before assuming it's worthy of this section of the forum.

shadowphile
after some playing around I couldn't get the suggested approach to work because it does not take into account transparency.
I can have a switched-on flashlight inside a closed up (transparent) jar and it will still light up the room with my script.
They can even be nested, so a clear jar inside a bigger clear jar with a flashlight will light up the room, even though both jars are closed.

HegemonKhan
isn't the definition of transparent, mean that light passes through it (hence its transparency) ? So, isn't transparency working correctly as it should be ?? Though, obviously you'll need a work around (or make your own code) if you want the transparency effects, but without the effect of its light transparency.

just being nick-picky with the definition of transparent, and not offering any help with a solution, so ignore this post, hehe.

Pertex
shadowphile wrote:after some playing around I couldn't get the suggested approach to work because it does not take into account transparency.

Hmmm, I tested a lightsource within a transparent container within a transparent container in my inventory and it worked. Could you create a game file which demonstrates your problem?

shadowphile
I put a lamp set to a strong lightsource inside a closed transparent jar in my inventory, and I'm in a dark room.
I drop the jar and the room remains dark.
<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testTrans">
<gameid>84164ce6-68a5-48d1-8be2-e9ac8a8c7519</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<dark />
<darkroomdescription>it's dark</darkroomdescription>
<description>it's bright in here</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<object name="jar">
<inherit name="editor_object" />
<inherit name="container_open" />
<take />
<isopen type="boolean">false</isopen>
<transparent />
<listchildren />
<object name="lamp">
<inherit name="editor_object" />
<take />
<lightsource />
<lightstrength>strong</lightstrength>
</object>
</object>
</object>
</object>
<function name="ScopeVisibleLightsource" parameters="lightstrength" type="objectlist">
result = ScopeVisibleNotHeld()
result = ListCombine(result, ScopeReachableInventory())
lightobjects = NewObjectList()
foreach (obj, result) {
if (GetBoolean(obj, "lightsource") and GetString(obj, "lightstrength") = lightstrength) {
list add (lightobjects, obj)
}
}
exits = ScopeExits()
foreach (obj, exits) {
if (GetBoolean(obj, "lightsource") and GetString(obj, "lightstrength") = lightstrength) {
list add (lightobjects, obj)
}
}
return (lightobjects)
</function>
</asl>

Pertex
You are right! I think,this is the better way:

 <function name="ScopeVisibleLightsource" type="objectlist" parameters="lightstrength">   
result = ScopeVisible()
lightobjects = NewObjectList()
foreach (obj, result) {
...

tbritton
Great tip for working with lightsources. I slightly modified the code since I didn't want the room description repeated if you turned the lamp on or off in a lighted room.

Code for after switching on:
dark = CheckDarkness()
if (dark) {
lantern.lightstrength = "strong"
lantern.lightsource = True
ShowRoomDescription
}
else {
lantern.lightstrength = "strong"
lantern.lightsource = True
}


Code for after switching off:
lantern.lightstrength = "weak"
lantern.lightsource = True
dark = CheckDarkness()
if (dark) {
ShowRoomDescription
}

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

Support

Forums