dynamic_menu object
This method allows you to specify a user defined function that can be used continually from within the menu loop.
bool set_callback(menu_callback@ callback, string user_data)
Parameters:
callback
The handle to a callback function that will be called continually within the menu loop.
user_data
A string containing any custom data that will be sent to the callback.
Return value:
true on success, false on failure.
Remarks:
The callback function should contain two parameters; the handle to a dynamic_menu object and a string for the custom user data. It should return an integer, which should be 0 if you wish the menu to continue executing. If any other value than 0 is returned, the menu will stop and the return value from the callback will be returned as the menu result.
This method is useful for performing various operations from within the menu, such as poling for network events, allowing the user to change the music volume, or playing sounds when the menu position has changed.
Example:

    // Make a simple menu and use a callback. The callback will check the current position with a variable and play a sound if the position has changed.

    #include "dynamic_menu.bgt"

    sound movement;
    dynamic_menu menu;
    int menu_position;

    void main()
    {
    int menu_result;
    menu.allow_escape=true;
    menu.wrap=false;
    menu.set_callback(check_menu_events, "");
    menu.add_item_tts("Start game.");
    menu.add_item_tts("Test speakers.");
    menu.add_item_tts("Exit.");
    menu_result=menu.run("Please choose an option", true);
    if(menu_result==-1)
    {
    alert("Error", "There was an error loading the menu.");
    exit();
    }
    if(menu_result==0)
    {
    alert("Option", "Escape was pressed. Exiting.");
    exit();
    }
    if(menu_result==1)
    {
    alert("Option", "Option selected was start game.");
    }
    if(menu_result==2)
    {
    alert("Option", "Option selected was test speakers.");
    }
    if(menu_result==3)
    {
    alert("Option", "Option selected was exit. Exiting.");
    exit();
    }
    }

    int check_menu_events(dynamic_menu@ game_menu, string data)
    {
    if(game_menu.get_position()!=menu_position)
    {
    movement.load("menumove.wav");
    movement.play_wait();
    movement.close();
    menu_position=game_menu.get_position();
    }
    return 0;
    }