I had to do this when I wanted the character to say something when he approached the edge of a Walkable Area, in this case the sea:
Code: ags
function region1_WalksOnto()
{
#define i 5 //total messages
String message[i];
message[0] = "Nope, I can't stand salty water.";
message[1] = "I don't want wet feet!";
message[2] = "Not going to ruin my shoes man...";
message[3] = "No way, what if there are sharks?";
message[4] = "Hmmm, I don't think I can swim...";
int index = Random(i - 1);
player.Say(message[index]);
}