Torch already on.

OurJud
15 Dec 2015, 16:24Can anyone see why this isn't working?
I have a command set for 'use torch; switch on torch; etc etc etc'
Then I run this script, which should be checking to see if the torch is on, so that a double command of 'switch on torch' should get "It's already on."
Instead, it just throws up the room description again.
I have a command set for 'use torch; switch on torch; etc etc etc'
Then I run this script, which should be checking to see if the torch is on, so that a double command of 'switch on torch' should get "It's already on."
Instead, it just throws up the room description again.
if (game.pov.parent = bunker) {
msg ("The moist walls glisten in the light from the torch. On the floor, scattered bones are caught in the beam.<br/><br/>The tunnel continues west. Way out is east.")
SetObjectFlagOn (player, "torchon")
}
else {
if (game.pov.parent = bunker) {
ShowRoomDescription
SetObjectFlagOn (player, "torchon")
}
if (game.pov.parent = bunker tunnel) {
ShowRoomDescription
SetObjectFlagOn (player, "torchon")
}
if (game.pov.parent = bunker room) {
ShowRoomDescription
SetObjectFlagOn (player, "torchon")
}
if (GetBoolean(player, "torchon")) {
msg ("It's already on.")
}
else {
msg ("No need for a torch here.")
}
}

OurJud
15 Dec 2015, 16:32Never mind. The torch check if needed to go at the top of the list.
That's just another thing I can't get my head around with these damned ifs... that they have to go in order.
That's just another thing I can't get my head around with these damned ifs... that they have to go in order.
The Pixie
15 Dec 2015, 20:23The best way to do something like this is to think of all the times it will NOT work, and test for them.
Start from this:
If the torch is already turned on
If the player does not have the torch
If the battery is dead
If the room is well lit (name does not start "bunker")
Otherwise do it
Then build a series if if/else around that.
Start from this:
If the torch is already turned on
If the player does not have the torch
If the battery is dead
If the room is well lit (name does not start "bunker")
Otherwise do it
Then build a series if if/else around that.
if (GetBoolean(player, "torchon")) {
msg ("It's already on.")
}
else if (not Got(torch)) {
msg ("You don't have it.")
}
else if (torch.dead) {
msg ("It's dead.")
}
else if (not StartsWith(player.name.name, "bunker")) {
msg ("You don't need a torch here.")
}
else {
msg ("You turn the torch on.")
ShowRoomDescription
SetObjectFlagOn (player, "torchon")
}

OurJud
16 Dec 2015, 00:09Thanks, TP - most useful! I shall add this to my ever-growing library of useful scripts.