So what I'm trying to set up is a multi room fight. The player is ambushed while crossing a river and has to fight back with ranged attacks. I'm almost there. What I did is put each room inside of a bigger room, marked them as both objects and rooms, then had the player enter that room before entering the river. Next I marked each room as visible and scenery so that they don't show up as objects in the main room, but can still be seen for the next step. Finally, I turned each room into an open container so that the enemies can be seen from the player's room.
With all of that I actually can attack them by typing in the commands. The problem I'm having is that they don't show up if I click to use the item instead. Since they aren't actually in the room they don't show up in the list of targets. Is there anyone who would be able to help me with this final step? To put it another way I'm trying to use an item on an object in a container from within a different container. If that makes any sense at all.
I think this is one of the situations where you need to use the backdrop scope script.
I think it's on the game's "Advanced scripts" tab in the editor.
Within the backdrop scope script, there is a variable named items
which is a list of the objects the player can currently choose from. You should make the script check whether the player is in this situation, and if so, add the relevant enemies or other objects to the list.
This is something I thought about a lot when I was looking at the scope system a few years ago. Really, it should be possible for a 'use' object to have some attribute specifying the scope for what it can be used on; but the way the functions are arranged isn't really compatible with that.
Now I'm thinking about it, I can see a couple of relatively minor changes to the core code which might make this a bit more intuitive… allowing an object to have a scope which determines what objects will be suggested for the player to use it on. But that would still be a bit of an awkward bodge.
Let's pretend that I'm such an idiot when it comes to coding that I crashed the game attempting this. What would the script look like? This is what I came up with. Given that the game force closed after entering the river I'm assuming it could use some improvements. I'm just not sure which list you're referring to or what I add to it.
if (game.pov.parent = River 2) {
if (ListContains(ScopeVisible(), First Archer Kobold)) {
list add ("items", First Archer Kobold)
}
}
I crashed the game attempting this
The problem is that most of the scope commands will call this script again, causing an infinite loop. So you might need to do this without using ScopeVisible
. Unfortunately, the methods you need are sometimes a little complex.
I can't remember the names off the top of my head, but there is a function called something like GetNonTransparentParent
to find the outer room if the player is a container; and then ContainsVisible
to determine if the npc is both in that room and visible.
So something like…
if (ContainsVisible (GetNonTransparentParent (game.pov), First Archer Kobold)) {
if (not ListContains (items, First Archer Kobold)) {
list add (items, First Archer Kobold)
}
}
Nope. That wasn't it. Just to be sure I moved the archer to the starting room and tested the code again, but this doesn't make it appear as a target in the player's room. I also considered the possibility that the object's alias was messing it up somehow and tried it with a different object.
With that said knowing that advanced script can do it was enough for me to track down this which covers how to do the exact thing I'm trying to do. https://docs.textadventures.co.uk/quest/advanced_scope.html
There's a bit more I'll have to do to make it work since the fight is made up of multiple rooms, but I have actually been over complicating this to no end. From the looks of it none of the stuff I did in the first post was required. If I plug this into the advanced script page then I can use any item I want on anything in these two rooms as long as I'm in one of them.
if (game.pov.parent = River 2) {
foreach (obj, GetDirectChildren(Southern Bridge half)) {
list add (items, obj)
}
}
if (game.pov.parent = Southern Bridge half) {
foreach (obj, GetDirectChildren(River 2)) {
list add (items, obj)
}
}
Thank you for your help. I guarantee I never would have found that link without a starting point.