Creating A flashlight

ivyostrider
Hello, I am having trouble creating a flashlight for my game. When I looked up a way to make the object work automatically in all rooms, I found http://forum.textadventures.co.uk/viewtopic.php?t=3743 this topic, but I ran in to trouble following it: Not sure where to paste the code in which box after creating the function, Not sure how to find the function CheckDarkness, and how exactly to go putting in code once I found it.
Could someone help? Thanks!

HaganeSteel
This may or may not help, but in Carrion Fire, "Flashlight" is an attribute under the "player" object. It's not an object itself.

Flashlight is an integer that begins at 125. I have a turn script called "Flashlight" that runs throughout the entire game, and every time the player takes an action, I have the turn script set the attribute: player.Flashlight = player.Flashlight - 1.

To make the turn script run globally, you don't place it in a room. You place it in the "Objects" tree.

flashlight.png


CFPlayer.png


I also have a changed script. What this does is tell the game to end if the Flashlight integer reaches 0. Another thing it does is keep the Flashlight integer from going above 125. If player.Flashlight > 125, then player.Flashlight = 125.

changedflashlight.png


I did other things too. For example, when the player enters the final room to beat the game, I add +1 to player.Flashlight so that they won't die if their "Flashlight" is 1.

The Pixie
I would make the flashlight an object the player can pick up and turn on and off. here is a quick example game.
<!--Saved by Quest 5.6.5621.18142-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testy">
<gameid>ac0b3225-36cd-43ab-b1fc-eb4cdc4af74e</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<start type="script">
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="changedheight_rating" type="script">
player.height = GetHeight()
</attr>
</object>
<exit alias="south" to="second_room">
<inherit name="southdirection" />
</exit>
<object name="flashlight">
<inherit name="editor_object" />
<inherit name="switchable" />
<feature_switchable />
<take />
<battery type="int">23</battery>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Take</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Drop</value>
</inventoryverbs>
<look>An ordinary flashlight{if flashlight.switchedon:shining brightly}.</look>
<turnon type="script"><![CDATA[
if (ListContains(ScopeReachable(), this)) {
if (this.switchedon) {
msg (DynamicTemplate("AlreadySwitchedOn", this))
}
if (this.battery < 1) {
msg ("You try to turn on the flashlight, but the battery is dead.")
}
else {
msg ("You turn on the flashlight.")
do (this, "turn_on")
}
}
else {
msg (DynamicTemplate("DefaultTurnOn", this))
}
]]></turnon>
<turnoff type="script">
if (ListContains(ScopeReachable(), this)) {
if (not this.switchedon) {
msg (DynamicTemplate("AlreadySwitchedOff", this))
}
else {
msg ("You turn off the flashlight.")
do (this, "turn_off")
}
}
else {
msg (DynamicTemplate("DefaultTurnOff", this))
}
</turnoff>
<attr name="turn_on" type="script">
this.switchedon = true
EnableTurnScript (flashlight_turnscript)
msg (flashlight_turnscript.enabled)
SetObjectLightstrength (this, "strong")
</attr>
<attr name="turn_off" type="script">
DisableTurnScript (flashlight_turnscript)
this.switchedon = false
SetObjectLightstrength (this, "")
</attr>
</object>
<object name="plasticbox">
<inherit name="editor_object" />
<inherit name="container_open" />
<take />
<feature_container />
<transparent />
</object>
<object name="woodenbox">
<inherit name="editor_object" />
<inherit name="container_open" />
<take />
<feature_container />
</object>
</object>
<object name="second_room">
<inherit name="editor_room" />
<feature_lightdark />
<dark />
<description>An ornate room devoid of lights.</description>
<exit alias="north" to="room">
<inherit name="northdirection" />
<lightsource />
<lightstrength>weak</lightstrength>
</exit>
<object name="teapot">
<inherit name="editor_object" />
</object>
<exit alias="east">
<inherit name="eastdirection" />
</exit>
</object>
<turnscript name="flashlight_turnscript">
<enabled type="boolean">false</enabled>
<script>
flashlight.battery = flashlight.battery - 1
if (flashlight.battery = 10 and ListContains(ScopeReachable(), flashlight)) {
msg ("Your flashlight starts to flicker.")
}
if (flashlight.battery = 0) {
if (ListContains(ScopeReachable(), flashlight)) {
msg ("Your flashlight flickers and dies.")
}
do (flashlight, "turn_off")
}
</script>
</turnscript>
<walkthrough name="test">
<steps type="simplestringlist">
take flashlight
x flashlight
take plasticbox
take woodenbox
south
x flashlight
turn on flashlight
x flashlight
l
drop flashlight
l
turn on flashlight
put flashlight in woodenbox
take flashlight
put flashlight in woodenbox
l
close woodenbox
l
open woodenbox
put flashlight in plasticbox
l
close plasticbox
l
turn off flashlight
open plasticbox
turn off flashlight
l
turn on flashlight
l
look at flashlight
z
look at flashlight
turn on flashlight
</steps>
</walkthrough>
</asl>

There is an issue here about what happens if the player goes into a dark room without a torch. She can easily be trapped there as the exits are not accessible if they cannot be seen. One way around that is to have exits lit, but be aware of the issue

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

Support

Forums