Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to prevent exit when carrying objects

A topic by Garry Francis created Sep 01, 2019 Views: 125 Replies: 6
Viewing posts 1 to 7
Submitted

I want to prevent the player going in a certain direction while he/she is carrying anything. I've had to implement this as follows:

booleans {
  is_carried : boolean "true";
}
on_tick {
  : if (num_items_carried() > 0) {
    :set_true "is_carried";
  }
  :else {
    :set_false "is_carried";
  }
}
barriers {
  block_tree_up : block_path {
    from = room02
    to = room03
    block_when = is_carried
    message = You'll need both hands to climb the tree, so you'll have to drop your belongings first.
  }
  block_tree_down : block_path {
    from = room03
    to = room02
    block_when = is_carried
    message = You'll need both hands to climb the tree, so you'll have to drop your belongings first.
  }
}

This seems like a lot of work for something so simple. Is there a better way to do this?

This assumes the player uses U or D to climb the tree. I want CLIMB TREE to have the same restrictions. Is there a way to map CLIMB TREE to be equivalent to UP and DOWN?

I only use the barriers when it's easier, so in this case could you not just do a manual on_command match for "U_;CLIMB TREE", checking the location and number of carried objects instead? And then a similar one for "D _; CLIMB TREE".  If you want you can put an if - else in both of those to manually move the player up and down the tree with goto "tree", goto "bottom_tree"

This works, Garry...

   : match "climb tree;u _" {
         : if (is_at "tree_bottom") {
            : if (num_items_carried() > 0) {
               : print "You're carrying too much!";
               : done;}
            : else {
               : print "You carefully climb up the tree...";
               : press_any_key;
               : goto "tree_top";
               : redescribe;}}}

Actually, if you swap the order of climb tree and U in that command match, the system will automatically detect UP as a valid exit when next to the tree without any objects.

   : match "u _;climb tree" {
         : if (is_at "crossroads") {
            : if (num_items_carried() > 0) {
               : print "You're carrying too much!";
               : done;}
            : else {
               : print "You carefully climb up the tree...";
               : press_any_key;
               : goto "start";
               : redescribe;}}}
           

You may, or may not, want UP signposted as a valid exit when next to the tree... in which case, that order trick is a neat way of fooling the system.

Submitted(+1)

Yeah, that looks much cleaner. I'll give that a try. Thanks Gareth.

Submitted(+1)

I didn't notice the issue you mentioned with the order of the commands in the match statement. After testing everything I could think of, I came up with the following. This seems to work quite nicely. Notice that I added CLIMB UP and CLIMB U, whereas U - understands U, UP, GO U and GO UP. I'm wondering if I can somehow add CLIMB and ASCEND as synonyms for UP. Too much to think about.

         : match "climb tree;climb up;climb u;u -"
         {
            : if (num_items_carried() > 0)
            {
               : print "You'll need both hands to climb the tree, so you'll have to drop your belongings first.";
            }
            : else
            {
               : goto "room03" ;
               : redescribe;
            }
         }
 And, of course, the equivalent for climbing down the tree.

Yes, you can manually assign aliases for nouns & verbs in the vocab section. Most of the time you won't want or need to... there is no requirement to make any entries in the vocab section these days. But some times it can simplify your code and make it easier to consider all possible entries by the player.