Does anyone have any advice on how they handle dynamic menus in a game, for example in my game people will enter different building which will all have different menus and sub menus and some of these items when selected will require different actions to be taken. For example entering one building a menu might come up with buy, sell, identify, talk, and leave another menu might have rest, save, talk, and leave. Basically its really easy to get the first menu, I have all my buildings marked with a different code, shop types are 1, inn's are two, etc... but my problem comes with the menu and navigating them.

I have it set up with 5 separate text boxes each one will be an option but I'm not sure how to set it up so once someone selects buy, items display and can be scrolled through and then when one of those is selected it knows to buy and go back to the first menu. I was currently doing it by classifying each option as a mode for example if they enter shoptype 1 it will run
Code:
displayOption(1, "buy",101,building1);
optionMode[1] = 101;
displayOption(1, "sell",102,building1);
optionMode[2] = 102;
displayOption(1, "identify",103,building1));
optionMode[3] = 103;
displayOption(1, "talk",104,building1));
optionMode[4] = 104;
displayOption(1, "leave",105,building1));
optionMode[5] = 105;
and then when you select an item it checks what mode, for example 101 means bring up the item list for building1 and all the items will have mode 110 which means buy item and go back to main menu once purchase is complete. Is there a much smarter way to do this because I get the feeling I'm missing a much easier way of programming this...

Thanks in advance, and lol, please don't laugh at me if my current way of doing it is that dumb...

-ChaseNYC