The input system gets the "d" key press. This then goes on to the logic _for that game turn_. However, _we cannot complete the command without first getting a choice of item to drop from the inventory menu_.
This is how I see the situation. The item-dropping is another state on top of the menu:
• State Stack [Gameplay -> Menu]
The menu state is on top of the stack, and so it's the only state being executed. Only the top-most state is ever executed by the state manager.
The menu state lets the user take one of these actions: Leave-Menu, Drop-Item, Equip-Item, etc.
- The menu's Input method keeps querying the input to take any of the above actions.
- In case key "d" is detected, the menu's Logic method pushes a new state to the stack, the Drop-Item state, and leaves its logic method immediately (so we don't risk pushing more states for other keys that were also detected for that frame). You don't necessarily need to leave the Logic method at this point if you do more stuff than just checking key actions - the important thing is that you stop taking action for other keys. You'd need to run the rest of the menu logic in case you have a 2D or 3D game and want animated characters and audio happening in the background while you're using the menu.
- The menu's Render method is then called, rendering the entire game by calling the rendering system. It draws all game text (in case of your text-only game).
After rendering, once the program returns to the main loop, the state manager keeps calling to top-most state. This time, instead of it being the menu, it's the Drop-Item state which was just pushed to the stack.
- So the state manager invokes the functions from the top-most state which is Drop-Item.
• State Stack [Gameplay -> Menu -> Drop-Item]
You know the Drop-Item state is only called if the user pressed "d" from the menu. So this state only keeps listening for whatever item the user wants to drop.
- The Drop-Item's Input method reads keyboard characters that are assigned to each slot in the menu.
- The Drop-Item's Logic method figures which item was selected and calls a chosenItem.Drop(), or InventoryDrop(chosenItem) etc. As soon as an item is detected and dropped, the Drop-Item state pops itself from the stack and leaves its Logic method.
- The Drop-Item's Render method is then called, drawing the screen text just like the menu was doing previously (same calls to the rendering system and all, so no visual difference except for new text that's being added from these actions), and then we go to the main loop.
- The state manager executes the top-most state, which is now the menu.
• State Stack [Gameplay -> Menu]
Menu is back executing, the item was dropped.
EDIT: Clarity.