Setting up random response when moving around unlit rooms

OurJud
18 Dec 2016, 00:45This is one of those cases of me catering for circumstances that are never going to crop up (why would a player try to move around in the dark?) but that's just me (and possibly Xan :) )
Anyway I initially prevented any movement without a light source, but now I want to allow it.
This is the original script:
if (GetBoolean(torch, "switchedon")) {
firsttime {
msg ("Room description")
}
otherwise {
msg ("Subsequent visits room description")
}
}
else {
msg ("It's too dark to move.")
}
Now, instead of having the above response when trying to move without a light source, I want the message to randomly pick from a list of four or five different message, such as 'You feel along the wall but it's hopeless without any light', 'You can't see a thing', 'You edge along slowly, but it' so dark you may as well be blindfolded'
How would I alter the above script to cater for this is?
hegemonkhan
18 Dec 2016, 00:59the easiest would be to use the 'random' text processor command:
http://docs.textadventures.co.uk/quest/text_processor.html
if (GetBoolean(torch, "switchedon")) {
firsttime {
msg ("Room description")
}
otherwise {
msg ("Subsequent visits room description")
}
}
else {
msg ({random:You feel along the wall but it's hopeless without any light:You can't see a thing:You edge along slowly, but it' so dark you may as well be blindfolded})
}
if you're going to reuse this stuff a lot, then you'll want to instead store your messages as items into a stringlist Attribute and use the 'GetRandomInt' and 'StringListItem', to select one of the items to display randomly.
Also/btw, instead of using the 'firsttime/otherwise' Script/Function, having to have two messages, you can just instead use the 'once' text processor command, and only having to have one message:
if (GetBoolean(torch, "switchedon")) {
msg ({once:You're in the dark forest, you hear the howling of wolves getting closer, you can try to climb up a tree, or try to run towards the sound of rushing water to the west}"You again find yourself in the dark forest")
}
else {
msg ({random:You feel along the wall but it's hopeless without any light:You can't see a thing:You edge along slowly, but it' so dark you may as well be blindfolded})
}

OurJud
18 Dec 2016, 01:14Great, thank you! The random text will be perfect for my needs.
I don't know why stuff like this doesn't sink in with me like it does with others. I should know this stuff the length of time I've been using it!
The once trick is also very useful!
I've got an awful lot of changes to go and make.

OurJud
18 Dec 2016, 02:05Once last question on this.
The random text works great, but if the player types 'l' (for look) without a light source, they get one of the random responses.
Is there any way to have 'l' force a response of It's too dark to see. when there's no light source, but only when they're in rooms that are dark (I obviously don't want this response if they type 'l' when they're outside or if the torch is on).
To be clear, I want to avoid this:
Steps lead down into the cellar, but it's pitch black down there.
> d
You gingerly make your way down, but you can't see anything (one of the random responses)
> l
You risk going down into the cellar without a light source (another random response)
hegemonkhan
18 Dec 2016, 02:12I think this probably requires finding the: template for the default message and/or the code that handles it, in the underlying/built-in (filter -> show library elements) code and changing it to an 'if' conditional for separating your two desired responses...
I don't know the underlying/built-in code stuff (library -> show library elements) that well, so best wait for Pixie, or Pertex, (or Jay if he's back), to help on this stuff.

OurJud
18 Dec 2016, 03:54Okay, thank you. I did consider setting up a custom global command for look
, but the if
script would require me to list every single room where a light source is required.
Something like:
if torch is switched off {
if player is in attic
if player is in cellar
if player is in bedroom3
etc
etc
etc
etc
msg ("You can't see anything")
}
Else
ShowRoomDescription
Which would be rather laborious.

OurJud
18 Dec 2016, 18:31I've been thinking about this, and can't get my head around whether this would work:
if (GetBoolean(torch, "switchedon")) {
firsttime {
msg ("Room description")
}
otherwise {
msg ("Subsequent visits room description")
}
}
else {
firsttime {
msg ({random:You feel along the wall but it's hopeless without any light:You can't see a thing:You edge along slowly, but it' so dark you may as well be blindfolded})
}
otherwsie {
msg ("It's too dark to see.")
}
}
hegemonkhan
18 Dec 2016, 20:14that will certainly work (though you've got a typo-misspelling-characters-out-of-order in your 2nd 'otherwise' that needs to be fixed up). If you want to check for the room, here's how:
if (CheckDarkness()) {
if (Got (torch) and GetBoolean(torch, "switchedon")) {
firsttime {
msg ("Room description")
}
otherwise {
msg ("Subsequent visits room description")
}
}
else {
firsttime {
msg ({random:You feel along the wall but it's hopeless without any light:You can't see a thing:You edge along slowly, but it' so dark you may as well be blindfolded})
}
otherwise {
msg ("It's too dark to see.")
}
}
} else {
firsttime {
msg ("Room description")
}
otherwise {
msg ("Subsequent visits room description")
}
}

OurJud
18 Dec 2016, 20:19Cheers, hege.
I think I can further secure my method by not making the random responses refer to specifics (such as stairs). If I just have a bunch of generic "You fumble about in the dark." messages, then it doesn't matter if they get a random response when they press 'l'.