Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

How do you prevent actions in dark room?

A topic by Garry Francis created Oct 15, 2019 Views: 134 Replies: 5
Viewing posts 1 to 3
Submitted

I have a dark room. What's the easiest way to prevent a player doing things in the dark room that they shouldn't be able to do because it's too dark to see, i.e. everything except movement (or they wouldn't be able to leave) and meta commands like score, inventory, save, load. Probably need an override as well, to allow for LIGHT TORCH.

Host

I just wrote a guide here :

https://adventuron.io/docs/tut/#AdvancedDarkness

is_movement_command () is a boolean function that tests the logical sentence for anything that matches a compass direction. Essentially the is_inaccessible_darkness_verb boolean dynamic variable returns true if it's not a compass direction, or quit, load, save, inventory, turns or look. You can then use that to print a message instead of performing any further actions when the state of the game is also dark (which is another boolean variable).

This blocks the get and examine commands and all other verbs.

The "light lamp" action appears ahead of the darkness override, so it's permitted to occur when it is dark.

If you have any question, I'm the one to fly to.  Read my mind.

start_at                 = start_room
locations {
   start_room : location "You are in a lovely treasure room." ;
}
objects {
   // The crown is in the same location as the player at the start, but GET is blocked
   // so cannot be taken even if the player knows it's there.
   crown : object "a gold crown" start_at = "start_room" ;
   // The lamp description is dynamic, based on the state of the lamp
   lamp  : object "a lamp{is_lamp_lit ? ` (lit)`}" start_at = "inventory" ;
}
booleans {
   is_lamp_lit : boolean "false" ;
   is_dark     : boolean_dynamic  {(
      is_at "start_room" && is_lamp_lit == false
   )}
   // Everything except [movement, quit, save, load,
   // inventory, turns, look] is banned in the dark.
   is_inaccessible_darkness_verb : boolean_dynamic {(
      (
         /* is movement command matches any system compass direction verb + all aliases */
         is_movement_command () ||
         verb_is "quit"         ||
         verb_is "save"         ||
         verb_is "load"         ||
         verb_is "inventory"    ||
         verb_is "turns"        ||
         verb_is "look"
      ) == false
   )}
}
on_command {
   // This comes before the darkness action block, so we can perform this action in the dark.
   : match "light lamp"  {
      : if (is_carried "lamp" && is_lamp_lit == false) {
         : set_true "is_lamp_lit" ;
         : print "You light the lamp" ;
         : press_any_key ;
         : redescribe;
      }
   }
   // Blocks everything except movement, quit, save, load, inventory, turns, look
   : if (is_dark && is_inaccessible_darkness_verb) {
      : print "You fumble in the dark." ;
      : done ;
   }
}
settings {
   // Tells Adventuron when to override the location description with
   // the darkness message (in the theme system messages), plus will remove direction list
   // and object list from the location layout (when is_dark resolves to true)
   dark_expression = is_dark
}
themes {
   my_theme : theme {
      colors {
         // Set the darkness pen colour to dark blue.
         dark_pen = 9
      }
      system_messages {
         it_is_dark = Darkness surrounds you.
      }
   }
}
Submitted

This works nicely, except that I use a lot of on_command{} blocks within the locations{} block for room-specific commands and these are apparently processed first, so I've moved the darkness check inside the general on_command block{} to the specific on_command block{} for the room. Fortunately for me, I only have one dark room.

Host

Put the code on the on_pre_command {} block to prempt the per-location on_command {} handlers. Updated the documentation to put it in this block. You may need to press F5.

Submitted

Thanks. My game is essentially finished, apart from a few small things like this. I want to start on the graphics next. I'm guessing that I'll have to do something special to have a dark room (or blank) image when it's dark and normal image when it's light. Is that correct?

Host

By default, all images are disabled in the dark , but I'll also be adding support for custom layouts for dark rooms in the next few days (which will let you have a special graphic per room or fallback graphic) when in the dark state.

For now, accept no image in the dark. I'll let you know when it's ready.