Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:52:59+00:00 2026-05-27T19:52:59+00:00

I’m currently making a C++ game. I have my main loop during which the

  • 0

I’m currently making a C++ game.
I have my main loop during which the logic is computed then the sprites etc are drawn
I would like to implement “dialog windows” : when you press a touch in front of a NPC, a dialog window pops up in the bottom of the screen and you are frozen until you press a key, BUT the game continues to run (the other characters are moving, etc) so the main loop is still runing.
I managed to do it just fine: when an object is activated, it sends a message to a dialog manager that display the text window while the game keeps running, so it looks like :

object::OnActivated() {
GameManager::doWindow("some text");
//the game is not blocked here, the game continues to run normally and will display a window on the next frame
}

Now the problem comes when I want some association action to happen after the dialog is over, or for instance if you selected “yes” to a question. I’d like to have an implementation that’d work like this:

object::OnActivated() {
GameManager::doWindow("some text");
if(GameManager::Accepted()) addGold(100);
}

The problem is that this check & actions will be performed as soon as the window event is created, NOT when the window is closed / acepted. Is there any way to do this, while keeping the associated action in the OnActivated() function? I have no idea how to do this properly without using function pointers, which would force me to have a certain signature for every method I could use as a result.
thanks

edit: I posted a bounty because I’d like to know what is the most “canonical” answer to this problem. I guess this is a very common issue (for a lot of applications and every modern games),
and I’d like to have a solution that is as flexible as possible, since I cannot list as of today all of the possible “consequences” that a dialog could trigger.
More info:
– each dialog would be triggered by objects deriving from a common “Entity” class
– different objects from the same class would almost always have different dialog/actions associated to them (for instance, all of the NPCs objects would not have the same dialogs)
– I don’t care about moving the “dialog logic” out of the OnActivated method or even outside of the Entity class. This would happen anyway because I’d like to have the ability to add “random” dialogs scenarios for each NPC, so the dialogs etc would be stored elsewhere
– BUT I’d like to keep the dialog logic itself as close as possible for a single dialog. Ideally I’d like to be able to do something like : ” result = dialogWindow(“question?”); if (result) { … }”. I’m not sure it’s possible though

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:53:00+00:00Added an answer on May 27, 2026 at 7:53 pm

    The Command Pattern is used to encapsulate code to be executed at a later time.

    In your situation, the object::OnActivated() function would create an appropriate command object and store it to be found later. When Yes/No is selected by the user, the command may be run without the code needing to know what particular command object happens to be there.

    Here’s an example of an “add gold” command object:

    class DialogResponseCommand
    {
    public:
      virtual run() = 0;
    };
    
    class AddGoldCommand : public DialogResponseCommand
    {
    public:
      AddGoldCommand( int amount ) : amount(amount) {}
      virtual run()
      {
        if(GameManager::Accepted())
          addGold(amount);
      }
    
    private:
      int amount;
    };
    

    Now, given some storage for an upcoming command:

    shared_ptr<DialogResponseCommand> dialog_command;
    

    You could have your OnActivated() create the command:

    object::OnActivated() {
      GameManager::doWindow("some text");
      dialog_command = make_shared<AddGoldCommand>(100);
    }
    

    And when the user finally makes a choice:

    dialog_command->run();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.