Portable Lightsource
Carrot
03 Jul 2013, 16:49Am I being thick?
I created an object, Lamp.
I made it switchable and I made it a lightsource.
But it seems to be always on. - Yet doesn't work as a lightsource when carried either.
I found this:
In another thread (Making a basic 'brass lantern' that)
I did that, and it solved the issue of the light not illuminating the room when it is carried.
Now how do I make the damnable thing switchable?
And is there any other neater solution than modifying a core file to sort out the carrying side of things?
I created an object, Lamp.
I made it switchable and I made it a lightsource.
But it seems to be always on. - Yet doesn't work as a lightsource when carried either.
I found this:
Pertex wrote:...
<function name="ScopeVisibleLightsource" type="objectlist" parameters="lightstrength">
result = ScopeVisibleNotHeld()
result = ListCombine(result, ScopeReachableInventory()) <---add this line
lightobjects = NewObjectList()
foreach (obj, result) {
In another thread (Making a basic 'brass lantern' that)
I did that, and it solved the issue of the light not illuminating the room when it is carried.
Now how do I make the damnable thing switchable?
And is there any other neater solution than modifying a core file to sort out the carrying side of things?

Pertex
03 Jul 2013, 20:24Carrot wrote:
I made it switchable and I made it a lightsource.
But it seems to be always on.
Sure, there is no build-in connection between switchable and lightsource, you have to do this by script.

Carrot wrote:
And is there any other neater solution than modifying a core file to sort out the carrying side of things?
No, not at the moment. I changed it in the corefiles and Alex has to accept the pull request, then it will be in the next version/nightly build.
Carrot
03 Jul 2013, 20:52Cheers. I looked at that but didn't like leaving a blank field. I should have just tried it 

Carrot
03 Jul 2013, 23:03Ok, that is excellent and I have it working.
I have one question. How do I prevent the player from dropping the light source in a dark room?
I know I can do it by naming each room in an "if" script, ie "if player is in this room or this room or this room etc... do not drop lamp"
I can see no way to query "if room is dark".
I am presuming it may work with "if object attribute equals" and an "expression" rather than an "object"
But I am not sure what to do.
I have one question. How do I prevent the player from dropping the light source in a dark room?
I know I can do it by naming each room in an "if" script, ie "if player is in this room or this room or this room etc... do not drop lamp"
I can see no way to query "if room is dark".
I am presuming it may work with "if object attribute equals" and an "expression" rather than an "object"
But I am not sure what to do.

jaynabonne
03 Jul 2013, 23:19Not sure, as I haven't experimented with lightness and darkness, but looking at CheckDarkness in coredescriptions.aslx, it appears a dark room will have a Boolean attribute "dark" set to true. So you can do:
to check if a room is dark.
if (GetBoolean(room, "dark"))
to check if a room is dark.
Carrot
03 Jul 2013, 23:22*runs off to try it*
[edit]
It worked (sort of), needed a slight tweak. And thanks to this thread -> How to: current location?, I found that tweak.
I set the script to expression, and both of the following codes worked
I currently have this in my test game
[edit]
It worked (sort of), needed a slight tweak. And thanks to this thread -> How to: current location?, I found that tweak.
I set the script to expression, and both of the following codes worked

(GetBoolean(game.pov.parent, "dark"))
(GetBoolean(player.parent, "dark"))
I currently have this in my test game
<object name="lamp">
<inherit name="editor_object" />
<inherit name="switchable" />
<alias>lamp</alias>
<take />
<switchedondesc>It is emitting a steady, bright light.</switchedondesc>
<switchedoffdesc>It is currently off.</switchedoffdesc>
<look>A simple lamp.</look>
<onswitchon type="script">
SetObjectLightstrength (lamp, "strong")
</onswitchon>
<onswitchoff type="script">
SetObjectLightstrength (lamp, "")
</onswitchoff>
<drop type="script">
if ((GetBoolean(game.pov.parent, "dark"))) {
msg ("You don't think it wise to leave a light behind when exploring dark places")
}
else {
msg ("You drop the lamp.")
}
</drop>
</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>
Carrot
04 Jul 2013, 10:35I wrote out the steps to add this through the GUI for another forum member in this thread: Flashlights, so thought I would add that here also:
Carrot wrote:[snip]
Make a switchable, portable lightsource:
[list=1]
[*]Create a new object - we will call it lamp.[/*:m]
[*]On the [Setup] tab, give it a description (Text). e.g. A simple lamp.[/*:m]
[*]On the [Inventory] tab, mark the check-box Object can be taken[/*:m]
[*]On the [Options] tab, make it Switchable from the drop-down menu.[/*:m]
[*]Add Extra object description when switched on:, e.g. It is emitting a steady light.[/*:m]
[*]Add Extra object description when switched off:, e.g. It is currently off[/*:m]
[*][list=i][*]Under after switching on the object:, click on [Add new script][/*:m]
[*]scroll down the options to the section marked Darkness and select Set object brightness and click [Add] at the bottom of the pop-up window.[/*:m]
[*]You will now hav 4 drop-down boxes, in the 2nddrop-down, choose the object we are making a switchable lightsource - in this case lamp[/*:m]
[*]and in the 4th drop-down, choose strong[/*:m][/list:o][/*:m]
[*]Under after switching off the object:, follow the instructions above, but leave the 4th drop-down blank.[/*:m][/list:o]
Making a carried lightsource illuminate a room:
[list=1][*]In the bottom left-hand corner of the GUI, click on Filter and place a check-mark next to Show Library Elements, if one is not already present.[/*:m]
[*]In the search box above the left pane type ScopeVisibleLightsource (it is not case sensitive) and search.[/*:m]
[*]Select ScopeVisibleLightsource from the list on the left, and at the top of the GUI there should be a yellowish bar that says From library CoreScopes.aslx, follow that bar across and click [Copy] (otherwise you will not be able to edit it).[/*:m]
[*]Scroll to the bottom of the GUI and click [Add new script][/*:m]
[*]Scroll down to Variables, select Set a variable or attribute and click [Add] at the bottom of the window.[/*:m]
[*]In the box next to Set variable type result[/*:m]
[*]and in the box next to expression type ListCombine(result, ScopeReachableInventory())[/*:m]
[*]This step, I don't know if it matters or not - at the top of the script window is a tool bar, on it click the up arrow until your newly created script sits between Set variable result = ScopeVisibleNotHeld() and Set variable lightobjects = new object list[/*:m][/list:o]
Preventing the player from dropping a light source in a dark area:
[list=1]
[*]Select your object from the left hand pane, e.g. lamp[/*:m]
[*]Select the [Inventory] tab.[/*:m]
[*]Under Drop select Run script from the drop down box[/*:m]
[*]Click [Add new script] and click [If] at the top of the window.[/*:m]
[*]Make sure the drop-down at the beginning of the If statement is set to expression and in the blank box next to it type (GetBoolean(game.pov.parent, "dark"))[/*:m]
[*]Click the [Add new script] directly below the if statement you just created and above the button [Add Else If], and click [Print] at the top of the window.[/*:m]
[*]Make sure the drop-down next to Print is set to message and type a message into the box to the right, e.g. You don't think it wise to leave a light behind when exploring dark places[/*:m]
[*]Click [Add Else] then click the [Add new script] that just appeared, click [Print] and add another message, e.g. You drop the lamp.[/*:m][/list:o]
Hope this is helpful (and that I have copied the steps out correctly!
Direct thanks goes to Pertex, and jayanbonne for help specific to my queries, and other threads I have already linked to.

Pertex
04 Jul 2013, 10:53If you don't mind I would add your tutorial to the wiki. Could you perhaps create some screenshots of the scripts or append your game file so that I can create the images?
Carrot
04 Jul 2013, 11:29Pertex wrote:If you don't mind I would add your tutorial to the wiki. Could you perhaps create some screenshots of the scripts or append your game file so that I can create the images?
Sure I have just created a simple 2 room game to showcase these options

[edit]
This includes adding the verbs "Switch on" and "Switch off" to the Inventory verbs pane. (should this not be a default action for switchable, takable objects?)
[edit#2]
Note also the conditional script for moving to a dark room placed on the exit of the light room.