Ok, so... let's assume you're building your game on the default WME template.
If you look into the script\game.script, you'll find the on "RightClick" event handler. It's executed whenever the player right-clicks some some object. Notice that the script stores the clicked object in a global variable called MenuObject.
...
// store the clicked object in a global variable MenuObject
MenuObject = Game.ActiveObject;
...
It's convenient, because we'll need this information later.
Still in scripts\game.script, inside the on "RightClick" handler. There's a piece of code displaying the menu:
...
// and show the right-click menu
WinMenu.Visible = true;
...
We'll modify it to call a method inside the menu window first:
...
// tell the window to disable/enable action buttons
WinMenu.SetState();
// and show the right-click menu
WinMenu.Visible = true;
...
We added a SetState() method call. Now we'll add said method to the action window. Its script is located in interface\menu\menu.script.
Edit the script and add the following code:
method SetState()
{
var Btn;
// handle the LookAt button
Btn = this.GetControl("LookAt");
if(MenuObject.CanHandleEvent("LookAt")) Btn.Disabled = false;
else Btn.Disabled = true;
// handle the Take button
Btn = this.GetControl("Take");
if(MenuObject.CanHandleEvent("Take")) Btn.Disabled = false;
else Btn.Disabled = true;
// handle the Talk button
Btn = this.GetControl("Talk");
if(MenuObject.CanHandleEvent("Talk")) Btn.Disabled = false;
else Btn.Disabled = true;
}
This new method checks if the MenuObject (i.e. the right-clicked one) can handle certain events, and it enables or disables the menu buttons appropriately.
Whether a scene object "can handle" events is determined by the fact if their script contains even handlers such as
on "LookAt"
{
actor.Talk("What a nice thing. I wonder what it is.");
}
And that's it. Of course, you can define your own set of "verbs", such as "climb" etc.