Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Right now I want to know if an  NPC is in a certain room before I enter. If it was available, I'd use 'If parent_of "NCP"=="certain room" { Print "You don't want to go in there!'. But currently I've got a flag called 'npcisinroom' that I turn on and off instead. Is there another way to tell if a certain object is in a certain room without using parent_of? Perhaps I can use conditions on a barrier - but the NPC is behind a lockable door, so there is already a barrier there, which seems to complicate things.

I've come across something similar with containers (which I know are not properly implemented yet). For example, I have an openable cupboard with something inside that I want to see if I open it. Without a ready made container facility, I flag the object with a boolean 'isincupboard'. Then when I open the cupboard I create the object (so I can see it), then either close the cupboard without taking the object (isincupboard stays true, object is destroyed when cupboard closes) or take the object before closing the cupboard (isincupboard set to false, taken object is not destroyed).

As always with these things, there may be a simpler way that I just haven't seen (I'm not an experienced coder) but that's my current workaround.

(1 edit)

This doesn't work (in 8-bit mode) yet, but I'll work on mapping is_within_direct {}.

start_at = lake
locations {
   forest : location "You are in a forest." ;
   lake   : location "You are by a lake" ;
}
objects {
   lamp  : object "a lamp" at = "forest" ;
}
connections {
   from, direction, to = [
      forest, south, lake, 
   ]
}
on_tick {
   : if (is_within_direct { outer -> ( "forest" ) inner -> ( "lamp" )  }) {
      : print "The lamp is in the forest (directly)." ;
   }
   : else {
      : print "The lamp is NOT in the forest (directly)." ;
   }
}

This is now working in 8-bit compatibility mode.

Thanks for your efforts Chris!

Here's another hacky way to test if the NPC is in another room. I'm pretty sure this will work in 8-bit mode.

   : match "test me" {
      : goto "new_room";
      : if (is_beside "npc") {
         : print "The npc is there.";
      }
      : else {
         : print "The npc isn't there.";
      }
      : goto "old_room";
      : done;
   }

I will try it, thanks.

Regarding items in containers, I do this a lot. Here is some sample code from 'Seeker of Magic'. It is probably more complicated than what you need, but you can simplify it to suit your needs. You start out with a tin box. The tin box can be opened and closed. If you examine it when it is initially opened, you can see that it contains a silver key and a parchment. You can take these, providing you have room in your inventory, but you can't put them back again. (This is the only down side.) Note that there is only one boolean used to keep track of the state of the tin box. It uses has_not_created to keep track of whether or not the objects have been removed from the box.

// Tin box
   : match "examine box" {
      : if (is_present "tin_box") {
         : append "It's dark grey and dusty from the ashes. ";
         : if (is_box_open) {
            :if (has_not_created "silver_key" && has_not_created "parchment") {
               : print "It contains a silver <key<13>> and a <parchment<13>>.";
               : done;
            }
            :if (has_not_created "silver_key") {
               : print "It contains a silver <key<13>>.";
               : done;
            }
            :if (has_not_created "parchment") {
               : print "It contains a <parchment<13>>.";
               : done;
            }
            : print "It's empty.";
            : done;
         }
         : else {
            : print "It's closed.";
            : done;
         }
      }
   }
   : match "open box" {
      : if (is_present "tin_box" && is_box_open) {
         : print "It's already open.";
         : done;
      }
      : set_true "is_box_open";
      :if (has_not_created "silver_key" && has_not_created "parchment") {
         : print "It contains a silver <key<13>> and a <parchment<13>>.";
         : done;
      }
      :if (has_not_created "silver_key") {
         : print "It contains a silver <key<13>>.";
         : done;
      }
      :if (has_not_created "parchment") {
         : print "It contains a <parchment<13>>.";
         : done;
      }
      : print "It's empty.";
      : done;
   }
   : match "close box" {
      : if (is_present "tin_box" && !is_box_open) {
         : print "It's already closed.";
         : done;
      }
      : set_false "is_box_open";
      : print "It's now closed.";
      : done;
   }
// Key
   : match "examine key" {
      : if (is_present "silver_key" || (is_present "tin_box" && is_box_open && has_not_created "silver_key")) {
         : print "It looks like it's made of silver.";
         : done;
      }
   }
   : match "get key" {
      : if (is_present "tin_box" && is_box_open && has_not_created "silver_key") {
         : if (items_carried() < item_limit()) {
               : pocket "silver_key";
               : print "You take the <key<13>> out of the tin <box<13>>.";
               : done;
         }
         : else {
            : print "You can't carry any more.";
            : done;
         }
      }
   }
// Parchment
   : match "examine parchment" {
      : if (is_present "parchment" || (is_present "tin_box" && is_box_open && has_not_created "parchment")) {
         : print "It's dry and brittle and slightly singed around the edges.";
         : done;
      }
   }
   : match "get parchment" {
      : if (is_present "tin_box" && is_box_open && has_not_created "parchment") {
         : if (items_carried() < item_limit()) {
               : pocket "parchment";
               : print "You take the <parchment<13>> out of the tin <box<13>>.";
               : done;
         }
         : else {
            : print "You can't carry any more.";
            : done;
         }
      }
   }
(+1)

Thanks Garry - this is a clever solution. I'll file it away for future reference. I have a  boolean tagged to each object, which works well enough but could get unwieldy if I have a box full of stuff.  In my version,  I could put the objects back in the containers if I wanted to code that in as well. But as it is, it's not necessary for the game play, so I've got a 'there's no point in doing that!' type message instead, which is familiar adventure game shorthand for 'you could have done that, if the author had bothered to code it...'