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)." ;
}
}
}
}