1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resolved getMessages returning incorrect values over time

Discussion in 'Developer Support' started by Fontkodo, Oct 21, 2015.

  1. Fontkodo

    Joined:
    Jun 21, 2014
    Messages:
    350
    Likes Received:
    111
    As you can see the timestamps don't line up:
    [​IMG]
    I'm using the following code:
    Code (Text):
    1. System.out.println(Chatbox.getMessages().get(Chatbox.getMessages().size() - 1).getMessage().toString());
    to get the latest message in the chatbox.

    Steps to reproduce:
    Get the latest message and print out the contents

    Problem: It only works for a while, then it stops working, only solution is to relog.
    Proof that it works at first using the same code:
    [​IMG]

    It seems to happen when a 'News' message is displayed, where it stops working thereafter, though this could just be a coincidence, it could be due to the messages reaching the end of the chat, I don't know.

    [​IMG]
    --- Double Post Merged, Oct 21, 2015, Original Post Date: Oct 21, 2015 ---
    @Cloud

    Edit: Same behavior regardless of if timestamps are enabled or not

     
    #1 Fontkodo, Oct 21, 2015
    Last edited: Oct 21, 2015
  2. Best Answer:
    Post #6 by Cloud, Oct 22, 2015
  3. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    Did you try ChatBoxListener? Works fine for me.

    Code (Text):
    1. @Override
    2. public void onMessageReceived(MessageEvent e) {
    3.     System.out.println(e.getMessage());
    4. }
    Code (Text):
    1. (05:12:34) You can access Treasure Hunter from the side panel, and you can show the button again by logging out and back in.
    2. (05:13:00) A tasty fish.<br>GE guide price: 364 gp each
    3. (05:13:10) An enchanted ring.<br>GE guide price: 1,835 gp each
     
  4. Fontkodo

    Joined:
    Jun 21, 2014
    Messages:
    350
    Likes Received:
    111
    I'm using that but I need to delay until another message is sent and hence need getMessages to work.
     
  5. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,198
    Likes Received:
    1,041
    You could use a boolean as a switch?
     
  6. Fontkodo

    Joined:
    Jun 21, 2014
    Messages:
    350
    Likes Received:
    111
    I ended up doing that and it should work, but getMessages is still broken.
     
  7. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    getMessages isn't broken. It does not guarantee any order.
     
  8. Fontkodo

    Joined:
    Jun 21, 2014
    Messages:
    350
    Likes Received:
    111
    Could we get a way to sort them easily, or was this restriction put in place so people used ChatboxListener instead?
     
  9. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    It would be annoying to try and force the original order because the data comes in multiple "streams" that we then merge into a single list.
     
  10. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    Just make a concurrent list and and every time a message is received, add it to the list.
     
  11. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,937
    Likes Received:
    1,266
    Should be done in a bot specific context as this would be wasted usage for 99% of bots. May have been what you were suggesting, but just clarifying.
     
  12. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    It was a suggestion for @Furor
     

Share This Page

Loading...