SOLVED Usage of the plugin function WantsToDisplayMessage()

Discussion in 'Technical & Support' started by cosimo, Apr 24, 2014.

  1. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Hi,

    I'm trying to use WantsToDisplayMessage() to display a simple message in the chat
    when my plugin starts up correctly.

    I can't seem to do that. This is the relevant part of the code I'm trying to use:

    Code:
    bool WantsToDisplayMessage( MessageInfoV01 &msgInfo )
    {
        static bool displayed_welcome = false;
        static const char message_text[128] = "Delta-Best Plugin enabled!";
    
        if (! displayed_welcome) {
            displayed_welcome = true;
            msgInfo.mDestination = 1;     /* Chat */
            msgInfo.mTranslate = 0;     /* Don't translate */
            strncpy(msgInfo.mText, message_text, sizeof(message_text));
            return true;
        }
    
        return false;
    }
    
    What am I doing wrong?
     
    Last edited by a moderator: May 1, 2014
  2. fischkopf

    fischkopf Registered

    Joined:
    Sep 18, 2013
    Messages:
    58
    Likes Received:
    0
    Have you tried strlen instead of sizeof?
     
  3. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    You have to return true not false.
     
  4. Jorgen

    Jorgen Registered

    Joined:
    Oct 5, 2010
    Messages:
    558
    Likes Received:
    3
    Does it work if you send it to the message center (msgInfo.mDestination = 0; ) instead of the chat?
     
  5. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    I do return true, the first time only.
    Maybe I don't understand what you mean?
     
  6. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Tried, it doesn't work.
     
  7. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    Yeah I just slimed your code. So what is it doing? Crashing the game or just not sending the msg?
     
  8. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    No crash and no message. Rest of the plugin just works fine.
     
  9. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    I see the problem. You are initializing displayed_welcome everytime so it is always going to be set to false before you test. You need to move move that variable out of the function and into a global area.
     
  10. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Tried returning always true, doesn't work either.
    Tried deriving from V05 and V06. Same thing.
     
  11. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Oh, ok, then I misunderstood how static works in methods.
    Thanks, I'll try that. I'm sure it will work.
     
  12. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Nothing yet. I tried a few more things but it seems to never work for me.
     
  13. Jorgen

    Jorgen Registered

    Joined:
    Oct 5, 2010
    Messages:
    558
    Likes Received:
    3
    Here's a copy of code from a plug-in I wrote a while ago, and this does display a message in the message center:

    Code:
    bool LapDistancePlugin::WantsToDisplayMessage( MessageInfoV01 &msgInfo ) {
        if (mReportLapDistance == true) {
            msgInfo.mDestination = 0;
            msgInfo.mTranslate = 0;
            sprintf(msgInfo.mText, "Distance: %.0lfm", mLapDistance);
            mReportLapDistance = false;
            return true;
        }
        return false;
    }
    Edit: Ah, could it be the "<class name>::" prefix that is missing in your code? In that case it just becomes a local method I think, which would explain that it doesn't work. It's simply never called.
     
  14. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Bingo! Thanks Jorgen, that must be the problem, no doubt (the missing class name).
    I haven't tried yet, but I'm going to in a few minutes :)
     
  15. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    The missing class name was one problem.
    The other was that I have to wait until the EnterRealtime event before sending a message, or the message will be lost!
     
  16. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    Are you sure it is lost or is this something to do with the 15sec delay before the plugin is loaded? I hate this stupid delay when trying to troubleshoot.
     
  17. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Well, the plugin is indeed loaded before EnterRealtime.
    The message is triggered as soon as the plugin icon goes away now, so I'm happy :)
     
  18. Dan-Ove Brantholm

    Dan-Ove Brantholm Registered

    Joined:
    Dec 27, 2017
    Messages:
    51
    Likes Received:
    13
    Is this supposed to work with DX11? I have spent an hour now testing, and the function doesn't seem to be called at all.
     
  19. Dan-Ove Brantholm

    Dan-Ove Brantholm Registered

    Joined:
    Dec 27, 2017
    Messages:
    51
    Likes Received:
    13
    Solved... Was using the wrong plugin version...
     

Share This Page