Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

How to only accept one match?

A topic by Zuuri created Sep 13, 2019 Views: 130 Replies: 7
Viewing posts 1 to 4
Submitted

So I have a puzzle that requires putting in a code to unlock a safe. I can get it so that it only accepts the number, but I'm not sure how to go about printing something else for any other input. Is there a way to do this?

Host (1 edit)

We use the three functions here:

  • bool is_int (<STRING_FUNCTION>) 
  • string originaLverb()
  • string original_noun1()

is_int will return true if its input is a string representation of an integer number. (Assuming English language) original_verb() will return the first word the player typed. original_noun1() will return the first noun in a 3 or more word sentence, or ALWAYS the 2nd word in a 2 word sentence.

The sample shown below may be more than you need, as it supports DIAL XXXX, and XXXX as accepted combination formats.

: done will stop executing, therefore we simply put the bad combination processing code underneath the conditional good combination processing code. Check out the code snippet.

I have documented this here:

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

start_at  = office
locations {
   office : location "You are in an office." ;
}
objects {
   safe : scenery "a safe" start_at = "office" examine_message="The safe has a keypad.\nType DIAL XXXX (where XXXX is a number to try to open the safe).";
}
on_command {
   : if (is_present "safe") {
      : if (is_int (original_verb())) {
         : match "1234 _"  {
            : print "You enter the correct safe combination" ;
            : done ; // Stops it from matching anything else
         }
         : print "Wrong Combo" ;
      }
      : match "dial _"  {
         : if (is_int(original_noun1())) {
            : match "dial 1234"  {
               : print "You enter the correct safe combination" ;
               : done ; // Stops it from matching anything else
            }
            : print "Wrong Combo" ;
         }
         : else {
            : print "Please type DIAL XXXX (where XXXX is a number)." ;
         }
      }
   }
}
Submitted

Sorry about the late reply, I worked it into my code but I wanted it to only run once the number pad has been looked at. How should I go about doing this?

Host

Use a boolean to store that the safe has been examined, then only allow dialling a number if you have seen the keypad (has_seen_keypad == true).

start_at  = office
locations {
   office : location "You are in an office." ;
}
objects {
   safe : scenery "a safe" start_at = "office";
}
booleans {
   has_seen_keypad : boolean "false" ;
}
on_command {
   : if_examine "safe"  {
      : print "The safe has a <KEYPAD<12>>.\nIt looks like you need to <DIAL<13>> a 4 digit combination (e.g. <DIAL 0000<14>>)." ;
      : set_true "has_seen_keypad" ;
      : done ;
   }
   : match "dial _"  {
      : if (is_present "safe" && has_seen_keypad == true) {
         : if (is_int(original_noun1())) {
            : match "dial 1234"  {
               : print "You enter the correct safe combination" ;
               : done ; // Stops it from matching anything else
            }
            : print "Wrong Combo" ;
         }
         : else {
            : print "Please type DIAL XXXX (where XXXX is a number)." ;
         }
      }
      : else {
         : print "Dial what?" ;
      }
   }
}
Submitted

That's what I had been doing with other things, I'm glad to see it's right. Thank you so much!

Submitted

If I understand you correctly, try something like this:

: match "enter 1234" {
   : if (is_safe_locked) {
      : set_false "is_safe_locked";
      : print "Click.";
      : done;
   }
: else {
      : print "It's already unlocked.";
      : done;
   }
}
: match "enter _" {
   : print "Nothing happens.";
   }
}

Make sure the specific match comes before the general match. Obviously, you've got to do any other tests necessary such as making sure you're in the correct room.

Host

10 / 10 for brevity.

Submitted

Whoops. You got in before me. You must have answered while I was typing mine up.